0

I have a CloudFormation stack that deploys various AWS resources, S3 bucket excluded, i create the S3 Bucket (To fill with my zipped Lambdas) in my GitHub Actions workflow main.yml file which works fine, when i delete the deployed CloudFormation Stack, the S3 bucket i configure stays up (obviously). How could i automate this however?

name: Deploy to AWS

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      # ...

      - name: Create S3 bucket
        run: |
          aws s3api create-bucket --bucket sumting-2-lambdas --region eu-central-1 --create-bucket-configuration LocationConstraint=eu-central-1

      # ...

      - name: Deploy CloudFormation Stack
        run: |
          aws cloudformation deploy \
            --template-file template.yaml \
            --stack-name sumting-2 \
            --capabilities CAPABILITY_IAM

      # ...

So far i haven't tried much since i can't figure out a way to do this as optimal as possible.

  • 3
    To delete a non-empty bucket from CloudFormation you would have to use a custom resource (https://stackoverflow.com/questions/40383470/can-i-force-cloudformation-to-delete-non-empty-s3-bucket), but since you are running this from a CI system you could just run a `aws s3 rm s3://... --recursive` before running the cloudformation deletion – Paolo May 17 '23 at 07:32

0 Answers0