aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
184 stars 62 forks source link

S3 bucket not removed after PR is merged #2139

Closed nam-truong-le closed 2 weeks ago

nam-truong-le commented 3 weeks ago

Environment information

System:
  OS: macOS 15.0.1
  CPU: (8) arm64 Apple M3
  Memory: 96.69 MB / 24.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 22.8.0 - ~/.nvm/versions/node/v22.8.0/bin/node
  Yarn: undefined - undefined
  npm: 10.8.2 - ~/.nvm/versions/node/v22.8.0/bin/npm
  pnpm: 9.12.2 - ~/.nvm/versions/node/v22.8.0/bin/pnpm
NPM Packages:
  @aws-amplify/auth-construct: 1.3.1
  @aws-amplify/backend: 1.5.0
  @aws-amplify/backend-auth: 1.2.0
  @aws-amplify/backend-cli: 1.2.9
  @aws-amplify/backend-data: 1.1.4
  @aws-amplify/backend-deployer: 1.1.4
  @aws-amplify/backend-function: 1.7.0
  @aws-amplify/backend-output-schemas: 1.3.0
  @aws-amplify/backend-output-storage: 1.1.2
  @aws-amplify/backend-secret: 1.1.3
  @aws-amplify/backend-storage: 1.2.1
  @aws-amplify/cli-core: 1.1.3
  @aws-amplify/client-config: 1.4.0
  @aws-amplify/deployed-backend-client: 1.4.1
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.8
  @aws-amplify/platform-core: 1.1.0
  @aws-amplify/plugin-types: 1.3.0
  @aws-amplify/sandbox: 1.2.2
  @aws-amplify/schema-generator: 1.2.4
  aws-amplify: 6.6.6
  aws-cdk: 2.162.1
  aws-cdk-lib: 2.158.0
  typescript: 5.6.3
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Describe the bug

S3 bucket is removed after PR is merged.

Bildschirmfoto 2024-10-22 um 15 18 46

Reproduction steps

ykethan commented 3 weeks ago

Hey @nam-truong-le, to confirm is this a Amplify Gen 1 or Gen 2 app? if this is a Amplify Gen 1 application this behavior is currently being tracked on https://github.com/aws-amplify/amplify-cli/issues/11173

nam-truong-le commented 3 weeks ago

This is a Gen 2 app.

ykethan commented 3 weeks ago

Hey @nam-truong-le, on a quick reproduction i was unable to reproduce this behavior in Ampify Gen 2 but did notice the storage resource name had a format as follows for a PR preview branch. image (1) Which suggests the buckets shows in the screenshot provided are from Amplify Gen 1 storage.

nam-truong-le commented 3 weeks ago

nope, I create this resource in backend.ts like this:

/*========== RESOURCES TO PROCESS RESULT FILES ==========*/
const resultFilesStack = backend.createStack("result-files-stack");
const resultFilesBucket = new Bucket(resultFilesStack, "ResultFilesBucket", {
  bucketName: `shop-app-result-files-${process.env.AWS_BRANCH}`,
});

It's not my main storage created by defineStorage.

ykethan commented 3 weeks ago

@nam-truong-le thank you for the clarification. It appears this is a custom S3 bucket. From the CDK documentation for S3 construct it appears the removalPolicy on the bucket is set to orphaned by default. you will need to adjust the policy to destroy on stack deletion.

nam-truong-le commented 2 weeks ago

Adding removalPolicy helps. Thank you!

ykethan commented 2 weeks ago

Closing the issue, do open a new issue if you require additional assistance.