Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 29, 2024

Cancel requests

You may cancel any put, get, or copy requests made by the Storage API by keeping a reference to the promise returned.

const promise = Storage.get('key');
Storage.cancel(promise, "my message for cancellation");
try {
await promise;
} catch (error) {
console.error(error);
// We can confirm the error is thrown by the cancellation here
if (Storage.isCancelError(error)) {
console.error(error.message); // "my message for cancellation"
}
}

Caveat

Since the cancellation requires original reference of the promise, you need to make sure the return value of the request has not been modified. Usually async function wraps the promise being returned into another promise. For example

async function makeRequest() {
return Storage.get('key');
}
const promise = makeRequest();
// This won't cancel the request
Storage.cancel(promise);