AWS CodePipeline - 在 CloudFormation 中部署:操作执行失败需要功能:[CAPABILITY_AUTO_EXPAND]
AWS CodePipeline - Deploy in CloudFormation: Action execution failed Requires capabilities : [CAPABILITY_AUTO_EXPAND]
我刚刚开始使用 AWS CI/CD 管道。我想制作一个简单的管道来部署 lambda 函数(以及后来的 api 网关):
在 CodeCommit 中提交 -> 在 CodeBuild 中准备 CloudFormation 包 -> 部署到 CloudFormation
CodeCommit 和 CodeBuild 工作得很好,但在部署阶段(在 CodePipeline 中)我总是得到这个错误:
CodePipeline Error
但是在 UI 中我不能 select CAPABILITY_AUTO_EXPAND,只有 CAPABILITY_IAM 并不能解决问题:
CodePipeline Deploy Config
如果我通过 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
我不知道如何通过 UI 做到这一点,但在 CloudFormation 中,您可以在 "Capabilities" 节点的模板中指定它,请参阅下面的 "Capabilities"。
以下只是一个片段,对于 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"
},
我(有点)解决了我在这个帖子中的答案的问题:aws CAPABILITY_AUTO_EXPAND console web codepipeline with cloudformation
看起来 AWS UI 只是不显示该选项,您需要通过 AWS cli 更新管道。
我刚刚开始使用 AWS CI/CD 管道。我想制作一个简单的管道来部署 lambda 函数(以及后来的 api 网关):
在 CodeCommit 中提交 -> 在 CodeBuild 中准备 CloudFormation 包 -> 部署到 CloudFormation
CodeCommit 和 CodeBuild 工作得很好,但在部署阶段(在 CodePipeline 中)我总是得到这个错误:
CodePipeline Error
但是在 UI 中我不能 select CAPABILITY_AUTO_EXPAND,只有 CAPABILITY_IAM 并不能解决问题:
CodePipeline Deploy Config
如果我通过 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
我不知道如何通过 UI 做到这一点,但在 CloudFormation 中,您可以在 "Capabilities" 节点的模板中指定它,请参阅下面的 "Capabilities"。
以下只是一个片段,对于 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"
},
我(有点)解决了我在这个帖子中的答案的问题:aws CAPABILITY_AUTO_EXPAND console web codepipeline with cloudformation
看起来 AWS UI 只是不显示该选项,您需要通过 AWS cli 更新管道。