无法执行AWS Pipeline错误:“调用PutObject操作时发生错误AccessDenied:访问被拒绝”

问题描述

已按照此处的教程尝试设置AWS管道:https://docs.aws.amazon.com/lambda/latest/dg/build-pipeline.html

但是管道连续失败,并显示以下错误日志:

enter image description here

以下是一些操作,我已经尝试过了:

  1. 允许S3完全访问与云形成和代码管道服务角色相关联的“ cfn-lambda-pipeline”角色。

enter image description here

enter image description here

  1. 允许公共ACL访问S3存储桶。

enter image description here

下面是我的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的角色。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...