Name:
interface
Value:
Extend your Amplify Gen 2 app with AWS Blocks — self-contained backend capabilities you compose into your existing backend.

Page updated Apr 29, 2024

NewDeploy web apps with Git or your AI coding agent using the latest AWS Amplify. Add managed databases and authentication as you grow. Explore the documentation.
Maintenance ModeYou are viewing Amplify Gen 1 documentation. Amplify Gen 1 has entered maintenance mode and will reach end of life on May 1, 2027. For existing Gen 1 projects, a migration guide and tooling are available to help you upgrade.
JavaScript v5Amplify JavaScript v5 has entered maintenance mode. We recommend upgrading to v6. A migration guide is available to help you upgrade from v5 to v6.

Cancel requests

These docs cover Amplify Gen 1. For new web apps, we recommend the latest AWS Amplify, with a simplified CLI and native integrations for databases, storage, and AI models. Get started with the latest AWS Amplify.

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);