1

我正在使用弹性 IP 和安全组创建一个实例。在添加输出部分之前,一切正常。将输出部分添加到现有模板后,我收到了无效的 templateBody 错误。该模板在没有“输出”部分的情况下可以正常工作。下面是相关代码:

    "Resources": {
        "InstanceProfile" : {
            "Type" : "AWS::IAM::InstanceProfile",
            "Properties" : {
              "Path" : "/",
              "Roles" : ["TEST_Role"]
            }
          },
        "Instance": {
            "Properties": {
                "IamInstanceProfile" : {"Ref" : "InstanceProfile"},
                "BlockDeviceMappings": [
                    {
                        "DeviceName": "/dev/sda1",
                        "Ebs": {
                            "VolumeSize": {
                                "Ref": "EBSVolumeSize"
                            }
                        }
                    }
                ],
                "ImageId": {
                    "Ref": "AMI"
                },
                "InstanceType": {
                    "Ref": "InstanceType"
                },
                "KeyName": {
                    "Ref": "KeyName"
                },
                "SecurityGroupIds": [
                    {
                        "Ref": "SecurityGroup"
                    }
                ],
                "SubnetId": {
                    "Ref": "Subnet"
                }
            },
            "Type": "AWS::EC2::Instance"
            },
        "EIPAddress": {
            "Type": "AWS::EC2::EIP"
        },
        "IPAssoc": {
            "Type": "AWS::EC2::EIPAssociation",
            "Properties": {
                "InstanceId": {
                    "Ref": "Instance"
                },
                "EIP": {
                    "Ref": "EIPAddress"
                }
            }
        },
    },
    "Outputs" : {
        "PublicIP": {
            "Value": { "Fn::GetAtt": [ "Instance", "PublicIp"]},
            "Description": "Public IP of the machine"
        }
    }

}
4

1 回答 1

1

我认为原因是你有额外的逗号

        }, # <---- here
    },
    "Outputs" : {
        "PublicIP": {
            "Value": { "Fn::GetAtt": [ "Instance", "PublicIp"]},
            "Description": "Public IP of the machine"
        }
    }

另外,如果您的实例不是 public,则模板将失败,因为私有实例没有PublicIp,因此您无法输出它。

更新完整模板(在us-east-1默认 VPC 中测试):

在此处输入图像描述

于 2020-07-29T05:59:13.167 回答