我正在尝试创建一个简单的(目前)云形成/代码管道集成,但是在为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)
出了什么问题?
输入template.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 *
生成变更集设置:
答案 0 :(得分:2)
这里的问题是,如果您在此处查看模板的代码段,则尚未将值传递给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值,则将不会有任何结果验证失败,因为实际上该值为None时,期望该参数存在一个字符串。
如果您改为这样做:
{
"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模板不应再通过验证失败。