How to reuse an AWS S3 bucket for multiple Serverless Framework deployments
Published in
4 min readMar 3, 2020
When using Serverless Framework, the default behaviour is the creation of a S3 bucket for each serverless.yml
file, since they are treated as separated projects.
As described in the documentation, when you run serverless deploy we have the following steps happening:
- An AWS CloudFormation template is created from your
serverless.yml
. - If a Stack has not yet been created, then it is created with no resources except for an S3 Bucket, which will store zip files of your Function code.
- The code of your Functions is then packaged into zip files.
- Serverless fetches the hashes for all files of the previous deployment (if any) and compares them against the hashes of the local files.
- Serverless terminates the deployment process if all file hashes are the same.
- Zip files of your Functions’ code are uploaded to your Code S3 Bucket.
- Any IAM Roles, Functions, Events and Resources are added to the AWS CloudFormation template.
- The CloudFormation Stack is updated with the new CloudFormation template.
- Each deployment publishes a new version for each function in your service.