CloudFormation创建EC2实例时MetadataOptions属性验证失败求助
CloudFormation EC2实例MetadataOptions配置错误排查
你遇到的属性验证失败问题,核心原因是**MetadataOptions的位置放错了**。它应该是AWS::EC2::Instance资源的Properties属性下的子配置,而不是和Properties同级。
在你的模板里,MetadataOptions被放在了EC2Server资源的根层级(和Properties平级),但CloudFormation的资源定义规则要求,所有实例相关的配置属性必须嵌套在Properties对象内部,所以系统会判定这个键是多余的,抛出错误提示。
修正后的模板代码
{ "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { "TagName": { "Type": "String", "Description": "The Name tag for the EC2 instance", "Default": "EC2Instance" }, "TagRole": { "Type": "String", "Description": "The Role tag for the EC2 instance", "Default": "WebServer" } }, "Resources": { "EC2Server": { "Type": "AWS::EC2::Instance", "Properties": { "InstanceType": "t2.micro", "ImageId": "ami-id", "KeyName": "test-key", "VpcId": "vpc-id", "SubnetId": "subnet-id", "SecurityGroupIds": [ "sg-id" ], "Tags": [ { "Key": "Name", "Value": { "Ref": "TagName" } }, { "Key": "Role", "Value": { "Ref": "TagRole" } } ], "MetadataOptions": { "HttpTokens": "optional", "HttpEndpoint": "enabled", "HttpProtocolIpv6": "disabled", "HttpPutResponseHopLimit": 1, "InstanceMetadataTags": "enabled" } } } } }
修正点:把原来在Properties外的MetadataOptions块,移动到Properties对象内部,和InstanceType、Tags等属性同级即可。
内容的提问来源于stack exchange,提问作者Vanaan
相关产品推荐
相关产品推荐

