json - 用于创建 EC2 的 AWS CloudFormation 模板 (JSON) - 意外错误
问题描述
开始测试 Cloud Formation 模板以使用 JSON 格式创建 EC2 实例,收到错误“每个参数对象必须包含一个类型成员”。我在网上找不到解决方案。
我已经搜索了这个错误,我发现的唯一解决方案是将“Type”:“String”添加到模板中,但它已经存在。
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "EC2 CloudFormation Template - Version 1.0",
"Metadata": {},
"Parameters": {
"InstanceType": {
"Description": "EC2 instance type",
"Type": "String",
"Default": "t2.small",
"AllowedValues": [
"t1.micro",
"t2.nano",
"t2.micro",
"t2.small",
"t2.medium",
"t2.large",
],
"ConstraintDescription": "must be a valid EC2 instance type."
},
"Mappings": {
},
"Conditions": {
},
"Resources": {
"EOTSS_EC2": {
"Type": "AWS::EC2::Instance",
"Properties": {
"DisableApiTermination": "false",
"ImageId": "ami-06bee8e1000e44ca4",
"InstanceType": { "Ref": "InstanceType" },
"Monitoring": "true",
"Tags": [
{
"Key": "Name",
"Value": "test"
}
]
}
}
},
"Outputs": {
}
}
}
当我将它作为新堆栈启动时出现的错误是“模板格式错误:每个参数对象都必须包含一个类型成员。”
解决方案
问题是您的模板没有很好地嵌套:Outputs
应该在外面EOTSS_EC2
,Resources
换句话说,应该在AWSTemplateFormatVersion
, Description
, Metadata
, Parameters
, Mappings
,Conditions
和Resources
.
{
"AWSTemplateFormatVersion":"2010-09-09",
"Description":"EC2 CloudFormation Template - Version 1.0",
"Metadata":{
},
"Parameters":{
"InstanceType":{
"Description":"EC2 instance type",
"Type":"String",
"Default":"t2.small",
"AllowedValues":[
"t1.micro",
"t2.nano",
"t2.micro",
"t2.small",
"t2.medium",
"t2.large"
],
"ConstraintDescription":"must be a valid EC2 instance type."
}
},
"Mappings":{
},
"Conditions":{
},
"Resources":{
"EOTSS_EC2":{
"Type":"AWS::EC2::Instance",
"Properties":{
"DisableApiTermination":"false",
"ImageId":"ami-06bee8e1000e44ca4",
"InstanceType":{
"Ref":"InstanceType"
},
"Monitoring":"true",
"Tags":[
{
"Key":"Name",
"Value":"test"
}
]
}
}
},
"Outputs":{
}
}
推荐阅读
- reactjs - 为什么反应wai-aria不在camelCase中?
- css - 是否可以用 CSS 中的图像替换 HTML 图像?
- python - Finding day of the week for a datetime64
- latex - Evaluate a function and assign to a constant to use as tick markin Tikz/pgfplots
- c# - Unity 一个一个或一个块地实例化预制件?(性能问题)
- file - 在 Golang 中的文件之间附加
- azure-pipelines - 找不到与模式匹配的测试程序集:**\*Test*.dll,!**\*TestAdapter.dll,!**\obj\**
- php - php 变量随处可用
- php - 生成具有关系的种子数据
- r - Linear interpolation for missing data in R