How do you reuse S3 buckets when deploying Lambdas without a server?

We recently used Serverless to handle the deployment of Lambda features in our AWS environment, but for each unique feature that is deployed, a new S3 bucket is created. This is inefficient, and for each stack created without a server, one bucket would be ideal. Is there any way to do this from the serverless.yml file? I tried to execute the following configurations of yml files for resources without any success.

1 - listing the bucket as a resource for use in yml

resources:
  Resources:
    ServerlessBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: serverless-test-bucket

Conclusion:

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 - Trying to reference a bucket in yml

resources:
  Resources:
    ServerlessBucket:
      Type: AWS::S3::Bucket
      Properties:
        Ref: serverless-test-bucket

Conclusion:

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
+4
source share
1 answer

Serverless, , , , 1.1.0.

serverless.yml, deployBucket . :

provider:
  name: aws
  runtime: python2.7
  stage: dev
  region: us-east-1
  deploymentBucket: bucketName
  iamRoleStatements:
    - Effect: "Allow"
      Action:
      -  "*"
      Resource: "*"
+5

Source: https://habr.com/ru/post/1657394/


All Articles