Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,35 @@ try {
```
</InlineFilter>

## Configure storage deletion behavior

By default, Amplify deletes the S3 bucket and all its objects when you remove the storage resource or delete your Amplify app. To preserve the bucket and its data, set `keepOnDelete` to `true`:

```ts title="amplify/storage/resource.ts"
export const storage = defineStorage({
name: 'myProjectFiles',
// Keep the bucket when the resource is removed
keepOnDelete: true,
});
```

| Setting | Behavior |
| --- | --- |
| `keepOnDelete: false` (default) | The bucket and all objects are deleted on removal. |
| `keepOnDelete: true` | The bucket is preserved on removal. You must delete it manually when no longer needed. |

<Callout warning>

Retained buckets continue to incur S3 storage costs. To avoid unexpected charges, delete retained buckets manually through the [AWS S3 console](https://console.aws.amazon.com/s3/) or the AWS CLI (replace `your-bucket-name`: `aws s3 rb s3://your-bucket-name --force`) when they are no longer needed.

</Callout>

<Callout info>

When using `npx ampx sandbox`, the bucket is always deleted regardless of the `keepOnDelete` setting. This prevents resource accumulation during development. The `keepOnDelete` setting only takes effect in deployed environments (connected Git branches).

</Callout>

## Connect your app code to the storage backend

The Amplify Storage library provides client APIs that connect to the backend resources you defined.
Expand Down
Loading