AWS云信息/代码管道参数:[ProjectId]必须有值



我正在尝试创建一个简单的(目前(云形成/代码管道集成,但在为云形成生成变更集时遇到了错误。

我让我的代码管道使用代码:- aws cloudformation package --template template.json --s3-bucket $S3_BUCKET --output-template template-export.yml构建输出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",
}
}
}
}

代码构建模板-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管理员
  • 输入工件:BuildArtifact

如果您在这里查看模板的片段,您的问题是您没有将值传递给云信息模板内的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模板不应该再验证失败。

最新更新