amazon-web-services - AWS Cloudformation / Codepipeline 参数:[ProjectId] 必须有值
问题描述
我正在尝试创建一个简单的(目前)云形成/代码管道集成,但是在为 cloudformation 生成变更集时出现错误。
我有我的代码管道使用代码构建输出 YML(下面的模板):- aws cloudformation package --template template.json --s3-bucket $S3_BUCKET --output-template template-export.yml
该导出然后进入云形成以创建变更集。
当它尝试创建变更集时,我收到此错误Parameters: [ProjectId] must have values (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: 4d20b24f-fd8b-11e8-9014-599dd1a18437)
出了什么问题?
输入模板.json
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"ProjectId": {
"Type": "String",
"Description": "Codepipeline cloudformation test"
},
"Stage": {
"Default": "",
"Type": "String",
"Description": "I am guessing some thing goes here"
}
},
"Resources": {
"LambdaExecutionRole": {
"Type": "AWS::IAM::Role",
"Description": "Creating service role in IAM for AWS Lambda",
"Properties": {
"RoleName": {
"Fn::Sub": "CodeStar-${ProjectId}-Execution${Stage}"
},
"AssumeRolePolicyDocument": {
"Statement": [{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
}
}]
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
],
"Path": "/"
}
},
"CreateUser": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Handler": "API/CreateUser.handler",
"Code": "API/CreateUser.py",
"Role": {
"Fn::GetAtt": [
"LambdaExecutionRole",
"Arn"
]
},
"Runtime": "python2.7",
}
}
}
}
来自 codebuild template-export.yml 的输出
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
ProjectId:
Description: Codepipeline cloudformation test
Type: String
Stage:
Default: ''
Description: I am guessing some thing goes here
Type: String
Resources:
CreateUser:
Properties:
Code:
S3Bucket: xxxx
S3Key: xxxx
Handler: API/CreateUser.handler
Role:
Fn::GetAtt:
- LambdaExecutionRole
- Arn
Runtime: python2.7
Type: AWS::Lambda::Function
LambdaExecutionRole:
Description: Creating service role in IAM for AWS Lambda
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Path: /
RoleName:
Fn::Sub: CodeStar-${ProjectId}-Execution${Stage}
Type: AWS::IAM::Role
其他信息:
Cloudformation 使用具有完整管理员权限的 IAM。allow *
生成变更集设置:
- 操作模式:创建或替换变更集
- 模板:BuildArtifact::template-export.yml
- 能力:CAPABILITY_NAMED_IAM
- 角色名称:cloudformation-admin
- 输入工件:BuildArtifact
解决方案
您的问题是您没有将值传递给 cloudformation 模板中的 ProjectId 参数,如果您在此处查看模板的片段:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"ProjectId": {
"Type": "String",
"Description": "Codepipeline cloudformation test"
},
"Stage": {
"Default": "",
"Type": "String",
"Description": "I am guessing some thing goes here"
}
},
您已为参数 Stage 提供了默认值,而 ProjectId 没有任何默认值,这意味着如果您没有在 CLI 命令中指定您希望 ProjectId 值是什么,那么它将什么都没有,这将导致验证失败,因为它期望有一个针对该参数的字符串,而实际上该值为无。
如果您改为这样做:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"ProjectId": {
"Default": "",
"Type": "String",
"Description": "Codepipeline cloudformation test"
},
"Stage": {
"Default": "",
"Type": "String",
"Description": "I am guessing some thing goes here"
}
},
这意味着该条目将是一个空字符串,但 cloudformation 模板不应再失败验证。
推荐阅读
- excel - 如何使用 VBA 使用选项按钮显示/隐藏工作表(Worksheet_Change 不是由选项值触发)
- sql-server - 使用自定义端口从远程测试 SQL Server 连接不起作用
- c# - 如何删除实时图表行图中的默认标签?
- javascript - 在网格中动态更改类型
- html - 水平对齐 div 并完全适合父级的宽度
- php - PHP显示未定义的索引“提交”
- ios - 如何为 IOS 的 xamarin.forms 中的单个 ContentPage 将方向从纵向更改为全部(横向/纵向)?
- node.js - 在开发中设置用于从 Angular 向 NodeJS 发送 API 请求的服务器端口
- android - RxJava2 | 如何处理一组可能
- spring-boot - 使用 Spring Data Rest 默认链接创建