最近我们采用了Serverless来处理我们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
答案 0 :(得分:8)
这已在最近的Serverless版本中添加,但该版本在某些操作系统上破坏了部署功能,因此该版本的版本为1.1.0。
这是在serverless.yml文件中通过添加deploymentBucket作为提供者下的字段来完成的。 例如:
provider:
name: aws
runtime: python2.7
stage: dev
region: us-east-1
deploymentBucket: bucketName
iamRoleStatements:
- Effect: "Allow"
Action:
- "*"
Resource: "*"
答案 1 :(得分:0)
这是添加到无服务器框架中的功能,但是有一个npm module可以帮助您实现此功能,将其检出。