【问题标题】:AWS CodePipeline CodeBuild SAM LambdaAWS CodePipeline CodeBuild SAM Lambda
【发布时间】:2019-01-03 13:39:02
【问题描述】:

我有一个来自 CodeCommit 的用于 Lambda (NodeJS) Auto Deploy 的管道。

我的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

【问题讨论】:

  • 你是不是先用sam package命令 sam package \ --template-file template.yaml \ --output-template-file packaged.yaml \ --s3-bucket REPLACE_THIS_WITH_YOUR_S3_BUCKET_NAME
  • @varnit 从日志中可以看到,执行的命令是aws cloudformation package --template-file samTemplate.yaml --s3-bucket codepipeline-551 --output-template-file outputSamTemplate.yaml
  • 它与代码构建无关,您必须在 ~/.awsconfig/credential 文件中设置一些用户,并且该用户必须有权访问您的 s3 存储桶,因此在您调用云形成包命令之前,您需要使用合适的 aws 凭据将此文件放置在您的环境中

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


【解决方案1】:

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

如果您像我一样,您可能在第一次设置时选择了default location 选项作为管道设置中的工件存储。在这种情况下,S3 存储桶本身可能有策略阻止访问。

对我来说,一旦我删除了存储桶策略,unable to upload artifact 错误就解决了,我的构建过程继续成功完成。

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2018-07-18
    • 2017-07-14
    • 2019-12-15
    • 2020-08-23
    • 1970-01-01
    • 2019-03-06
    • 2018-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多