问题描述
已按照此处的教程尝试设置AWS管道:https://docs.aws.amazon.com/lambda/latest/dg/build-pipeline.html
以下是一些操作,我已经尝试过了:
- 允许S3完全访问与云形成和代码管道服务角色相关联的“ cfn-lambda-pipeline”角色。
- 允许公共ACL访问S3存储桶。
下面是我的buildspec.yml
version: 0.2
phases:
install:
runtime-versions:
nodejs: 12
build:
commands:
- npm install
- export BUCKET=xx-test
- aws cloudformation package --template-file template.yaml --s3-bucket $BUCKET --output-template-file outputtemplate.yml
artifacts:
type: zip
files:
- template.yml
- outputtemplate.yml
下面是我的template.yaml
AWstemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
helloWorld
DZ Bank API Gateway connectivity helloWorld
Globals:
Function:
Timeout: 3
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./
Handler: app.lambdaHandler
Runtime: nodejs12.x
Events:
HelloWorld:
Type: Api
Properties:
Path: /hello
Method: get
解决方法
该错误实际上与CodeBuild有关,而不与CodePipeline有关。似乎CodeBuild没有对其附加服务角色的有效权限。
在控制台中,您可以通过执行以下操作找到附加的服务角色:
- 转到CodeBuild控制台
- 从左侧菜单中单击“构建项目”
- 单击要使用的构建项目旁边的单选按钮,然后在顶部菜单上单击“编辑”,然后选择“编辑源代码”选项。
- 页面底部将是一个标题为“服务角色权限”的部分,其下是Arn。
如果该IAM角色尚不存在,则需要被授予该权限(在您的情况下为“ s3:PutObject”)。
AWS在Create a CodeBuild service role文档中提供了完整的政策。
,与云形成和代码管道服务角色相关联的“ cfn-lambda-pipeline”角色。
S3权限应与 CodeBuild (CB)关联,因为CB将运行buildspec.yml
。因此,CB必须能够访问S3。
根据Update the build stage role部分中链接的教程,AmazonS3FullAccess
应添加到codebuild-lamba-pipeline-build-service-role
角色,而不是cfn-lambda-pipeline
或CodePipeline的角色。