最近,我们采用无服务器来处理 AWS 环境中 Lambda 函数的部署,但是对于部署的每个独特函数,都会创建一个新的 S3 存储桶。这是低效的,对于无服务器创建的每个堆栈都有一个存储桶是理想的。有没有办法从 serverless.yml 文件中做到这一点?我已尝试对资源进行以下 yml 文件配置,但均未成功。
1 - 将存储桶列为要在 yml 中使用的资源
resources:
Resources:
ServerlessBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: serverless-test-bucket
输出:
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 - 尝试引用 yml 中的存储桶
resources:
Resources:
ServerlessBucket:
Type: AWS::S3::Bucket
Properties:
Ref: serverless-test-bucket
输出:
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