AWS CodePipeline CodeBuild SAM Lambda

时间:2019-01-03 13:39:03

标签: amazon-web-services aws-codepipeline aws-codebuild

我有一条来自CodeCommit的Lambda(NodeJS)自动部署管道。

我的buildspec.yml

version: 0.1
phases:
 install:
  commands:
    - npm install
    - aws cloudformation package --template-file samTemplate.yaml --s3-bucket codepipeline-551 --output-template-file outputSamTemplate.yaml
artifacts:
  type: zip
  files:
    - samTemplate.yaml
    - outputSamTemplate.yaml

我的samTemplate.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Serverless Specification template describing your function.
Resources:
  KashIoTLambda:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: lambda.handler
      Runtime: nodejs8.10
      CodeUri: ./
      Description: ''
      MemorySize: 128
      Timeout: 3
      Role: 'arn:aws:iam::1234:role/abc-backend'
      Events:
        Api1:
          Type: Api
          Properties:
            Path: '/{proxy+}'
            Method: OPTIONS
        Api2:
          Type: Api
          Properties:
            Path: /MyResource
            Method: ANY
      Environment:
        Variables:
          REGION: ap-south-1

CodeBuild提及的角色所附加的策略允许访问“所有资源和所有S3”命令。

但是,我在构建日志中遇到以下错误

[Container] 2019/01/03 13:25:39 Running command npm install
added 122 packages in 3.498s
 [Container] 2019/01/03 13:25:44 Running command aws cloudformation package --template-file samTemplate.yaml --s3-bucket codepipeline-551 --output-template-file outputSamTemplate.yaml
 Unable to upload artifact ./ referenced by CodeUri parameter of ABCLambda resource.
An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
 [Container] 2019/01/03 13:25:46 Command did not exit successfully aws cloudformation package --template-file samTemplate.yaml --s3-bucket codepipeline-551 --output-template-file outputSamTemplate.yaml exit status 255
[Container] 2019/01/03 13:25:46 Phase complete: INSTALL Success: false
[Container] 2019/01/03 13:25:46 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: aws cloudformation package --template-file samTemplate.yaml --s3-bucket codepipeline-551 --output-template-file outputSamTemplate.yaml. Reason: exit status 255

1 个答案:

答案 0 :(得分:0)

检查存储桶本身的策略/权限。

S3 Bucket Policy

如果像我一样,您可能在初次设置时就选择了\1\2'relu'\4 \n # \1 = LeakyReLU\(alpha=a\)\(\1\) 选项作为管道设置中的工件存储。在这种情况下,S3存储桶本身可能存在阻止访问的策略。

AWS Pipeline Settings

对我来说,删除存储桶策略后,default location错误已解决,构建过程继续成功完成。

希望对您有帮助。