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

Kum*_*vek 3 amazon-s3 amazon-web-services aws-cloudformation aws-codepipeline aws-codebuild

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

但是管道不断失败并显示以下错误日志: 在此处输入图片说明

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

  1. 授予 S3 对与 Cloud Formation 和代码管道服务角色关联的“cfn-lambda-pipeline”角色的完全访问权限。

在此处输入图片说明

在此处输入图片说明

  1. 允许公共 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
Run Code Online (Sandbox Code Playgroud)

下面是我的 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
Run Code Online (Sandbox Code Playgroud)

Chr*_*ams 6

该错误实际上与 CodeBuild 而非 CodePipeline 有关。CodeBuild 似乎对其附加的服务角色没有有效的权限。

在控制台中,您可以通过执行以下操作找到附加的服务角色:

  • 转到 CodeBuild 控制台
  • 单击左侧菜单中的“构建项目”
  • 单击旁边的单选按钮构建您正在使用的项目,然后在顶部菜单上单击“编辑”并选择“编辑源”选项。
  • 页面底部将是一个标题为“服务角色权限”的部分,其下方是 Arn。

如果此 IAM 角色尚未存在,则需要为其授予所需的权限(在您的情况下为“s3:PutObject”)。

AWS 在创建 CodeBuild 服务角色文档中提供了完整策略。