1

我刚刚开始使用 AWS CI/CD 管道。我想制作一个简单的管道来部署 lambda 函数(以及后来的 api 网关):

在 CodeCommit 中提交 -> 在 CodeBuild 中准备 CloudFormation 包 -> 部署到 CloudFormation

CodeCommit 和 CodeBuild 工作得很好,但在部署阶段(在 CodePipeline 中)我总是收到此错误:

CodePipeline 错误

但在 UI 中,我无法选择 CAPABILITY_AUTO_EXPAND,只能选择 CAPABILITY_IAM,这并不能解决问题:

CodePipeline 部署配置

如果我通过 CLI 进行部署,我想我可以设置 CAPABILITY_AUTO_EXPAND 选项,但我想通过 UI 进行。

我能做些什么?

SAM 模板 yaml:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Returns the body
Resources:
  TestFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: test.handler
      Runtime: nodejs8.11.0
      CodeUri: ./
      Events:
        TestAPI:
          Type: Api
          Properties:
            Path: /test
            Method: POST
4

2 回答 2

0

我(有点)用这个线程中的答案解决了我的问题:aws CAPABILITY_AUTO_EXPAND console web codepipeline with cloudformation

看起来 AWS UI jsut 没有显示该选项,您需要通过 AWS cli 更新管道。

于 2019-02-12T10:26:01.423 回答
0

我不知道如何通过 UI 执行此操作,但在 CloudFormation 中,您可以在“功能”节点的模板中指定它,请参阅下面的“功能”。

以下只是一个片段,并不是 CloudFormation 的格式正确的 JSON。

 "Resources": {
"Pipeline": {
  "Type": "AWS::CodePipeline::Pipeline",
  "Properties": {
    "ArtifactStore": {
      "Location": {
        "Fn::Join": [
          "-",
          [
            "bubbleboy",
            {
              "Ref": "AWS::AccountId"
            }
          ]
        ]
      },
      "Type": "S3"
    },
    "Name": {
      "Ref": "AWS::StackName"
    },
    "RoleArn": {
      "Fn::GetAtt": [
        "PipelineRole",
        "Arn"
      ]
    },
    "Stages": [
      {
        "Actions": [
          {
            "ActionTypeId": {
              "Category": "Source",
              "Owner": "AWS",
              "Provider": "CodeCommit",
              "Version": "1"
            },
            "Configuration": {
              "RepositoryName": {
                "Ref": "Repo"
              },
              "BranchName": {
                "Ref": "Branch"
              }
            },
            "Name": "Source",
            "RunOrder": "1",
            "OutputArtifacts": [
              {
                "Name": "Source-Artifact"
              }
            ]
          }
        ],
        "Name": "SourceCode"
      },
      {
        "Actions": [
          {
            "ActionTypeId": {
              "Category": "Build",
              "Owner": "AWS",
              "Provider": "CodeBuild",
              "Version": "1"
            },
            "Configuration": {
              "ProjectName": {
                "Ref": "CodeBuildStage1NetCoreCodeBuildProject1"
              }
            },
            "Name": "Build",
            "RunOrder": "1",
            "OutputArtifacts": [
              {
                "Name": "Build-Artifact"
              }
            ],
            "InputArtifacts": [
              {
                "Name": "Source-Artifact"
              }
            ]
          }
        ],
        "Name": "Build"
      },
      {
        "Actions": [
          {
            "ActionTypeId": {
              "Category": "Deploy",
              "Owner": "AWS",
              "Provider": "CloudFormation",
              "Version": "1"
            },
            "Configuration": {
              "ActionMode": "CHANGE_SET_REPLACE",
              "StackName": {
                "Fn::Join": [
                  "-",
                  [
                    {
                      "Ref": "AWS::StackName"
                    },
                    "deploy"
                  ]
                ]
              },
              "Capabilities": "CAPABILITY_IAM",
              "RoleArn": {
                "Fn::GetAtt": [
                  "CreateChangesetCloudFormationRole1",
                  "Arn"
                ]
              },
              "ChangeSetName": {
                "Ref": "AWS::StackName"
              },
              "TemplatePath": "Build-Artifact::Deploy.template",
              "ParameterOverrides": {
                "Fn::Join": [
                  "",
                  [
                    "{ \"YadaYadaBubbleBoyWebApiBucket\": { \"Fn::GetArtifactAtt\": [ \"Build-Artifact\", \"BucketName\" ] }, \"YadaYadaBubbleBoyWebApiKey\": { \"Fn::GetArtifactAtt\": [ \"Build-Artifact\", \"ObjectKey\" ] },\"DbBranch\":\"",
                    {
                      "Fn::If": [
                        "isstaging",
                        "master",
                        {
                          "Ref": "Branch"
                        }
                      ]
                    },
                    "\"}\"DatabaseStack\":\"",
                    {
                      "Fn::If": [
                        "isstaging",
                        "database-stage",
                        {
                          "Ref": "DatabaseStack"
                        }
                      ]
                    },
                    "\"}"
                  ]
                ]
              }
            },
            "Name": "CreateChangeset",
            "RunOrder": "1",
            "InputArtifacts": [
              {
                "Name": "Build-Artifact"
              }
            ]
          },
          {
            "ActionTypeId": {
              "Category": "Deploy",
              "Owner": "AWS",
              "Provider": "CloudFormation",
              "Version": "1"
            },
            "Configuration": {
              "ActionMode": "CHANGE_SET_EXECUTE",
              "StackName": {
                "Fn::Join": [
                  "-",
                  [
                    {
                      "Ref": "AWS::StackName"
                    },
                    "deploy"
                  ]
                ]
              },
              "Capabilities": "CAPABILITY_IAM",
              "RoleArn": {
                "Fn::GetAtt": [
                  "ExecuteChangesetCloudFormationRole1",
                  "Arn"
                ]
              },
              "ChangeSetName": {
                "Ref": "AWS::StackName"
              }
            },
            "Name": "ExecuteChangeset",
            "RunOrder": "2"
          }
        ],
        "Name": "Deploy"
      }
    ]
  },
  "DeletionPolicy": "Delete"
},
于 2019-02-10T19:49:31.607 回答