Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

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

1 Answer

0 votes
by (44.4k points)

This can be done by adding deploymentBucket as a field inside the serverless.yml file. Below is an example:

provider:

  name: aws

  runtime: python2.7

  stage: dev

  region: us-east-1

  deploymentBucket: bucketName

  iamRoleStatements:

    - Effect: "Allow"

      Action:

      -  "*"

      Resource: "*"

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...