我在使用AWS CodeBuild构建和部署使用Serverless Framework创建的项目时遇到问题。
到目前为止,这是一个故事。
我已经跟随docs创建了无服务器项目的开头,然后离开了#34;" - 基本上," Hello World"。
然后我把项目放在git repo中。
然后,从CLI,我打电话给...
serverless deploy
......正如预期的那样,已经部署了lambda。一个好的开始。
议程的下一步是使用AWS CodeBuild进行构建和部署。
我在项目的根目录中添加了buildspec.yml
文件:
version: 0.1
phases:
install:
commands:
- npm install
- npm install -g serverless
- echo install done
build:
commands:
- serverless deploy
- echo build done
然后,使用AWS控制台/ Web界面,我定义了一个引用git repo的代码构建项目。
执行此操作时,AWS使用以下策略创建了IAM角色:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Resource": [
"arn:aws:logs:eu-west-1:************:log-group:/aws/codebuild/my-api-build",
"arn:aws:logs:eu-west-1:************:log-group:/aws/codebuild/my-api-build:*"
],
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
},
{
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::codepipeline-eu-west-1-*"
],
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:GetObjectVersion"
]
},
{
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::my-api-artifacts/*"
],
"Action": [
"s3:PutObject"
]
}
]
}
所以我按了#34;开始构建"在CodeBuild项目上,出现以下错误:
ServerlessError: User: arn:aws:sts::************:assumed-role/codebuild-my-api-build-service-role/AWSCodeBuild-********-****-****-****-************ is not authorized to perform: cloudformation:DescribeStackResources on resource: arn:aws:cloudformation:eu-west-1:************:stack/my-api-development/*
我已修复"通过将以下内容添加到由代码构建创建的策略...
{
"Effect": "Allow",
"Resource": [
"arn:aws:cloudformation:eu-west-1:*"
],
"Action": [
"cloudformation:*"
]
}
再次按下Start Build并获得:
An error occurred while provisioning your stack: ServerlessDeploymentBucket - API: s3:CreateBucket Access Denied.
我已修复"通过将以下内容添加到由代码构建创建的策略...
{
"Effect": "Allow",
"Resource": [
"arn:aws:cloudformation:eu-west-1:*"
],
"Action": [
"cloudformation:*"
]
}
Serverless Error ---------------------------------------
Missing required key 'Bucket' in params
Missing required key 'Bucket' in params
是什么意思?我应该在哪里看?答案 0 :(得分:1)
我通过在serverless.yml中添加(编辑)stage: prod
解决了这个问题。
最后,它看起来像这样。
provider:
name: aws
runtime: python3.6
stage: prod
credentials:
accessKeyId: <your-access-id>
secretAccessKey: <your-secret-access-key>