Recently we have adopted Serverless to handle the deployment of Lambda functions in our AWS environment, but for every unique function that is deployed, a new S3 bucket is created. This is inefficient and having a single bucket for every stack that Serverless creates would be ideal. Is there any way to do this from within the serverless.yml file? I have attempted the following yml file configurations for resources without any success.
1 - Listing the bucket as a resource to use in the yml
resources:
Resources:
ServerlessBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: serverless-test-bucket
Output:
Serverless: Packaging service...
Serverless: Removing old service versions...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading service .zip file to S3...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
............Serverless: Deployment failed!
Serverless Error ---------------------------------------
An error occurred while provisioning your stack: ServerlessBucket
- serverless-test-bucket already exists.
2 - Attempting to reference the bucket in the yml
resources:
Resources:
ServerlessBucket:
Type: AWS::S3::Bucket
Properties:
Ref: serverless-test-bucket
Output:
Serverless: Packaging service...
Serverless: Removing old service versions...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading service .zip file to S3...
Serverless: Updating Stack...
Serverless Error ---------------------------------------
Template format error: Unresolved resource dependencies
[serverless-test-bucket] in the
Resources block of the template