Json 云形成-设备索引不能为空

Json 云形成-设备索引不能为空,json,amazon-web-services,amazon-ec2,amazon-cloudformation,Json,Amazon Web Services,Amazon Ec2,Amazon Cloudformation,我一直在尝试让两个实例加入一个域,一个是dc。代码来自其中一个模板,但是它不允许我在修改后运行它。 当DC01实例启动时,我发现错误DeviceIndex不能为空。 这是DC01的代码 { "Resources": { "DC1": { "Type": "AWS::EC2::Instance", "Properties": { "BlockDeviceMappings": [

我一直在尝试让两个实例加入一个域,一个是dc。代码来自其中一个模板,但是它不允许我在修改后运行它。 当DC01实例启动时,我发现错误DeviceIndex不能为空。 这是DC01的代码

 {
    "Resources": {
        "DC1": {
            "Type": "AWS::EC2::Instance",
            "Properties": {
                "BlockDeviceMappings": [
                    {
                        "DeviceName": "/dev/sda1",
                        "Ebs": {
                            "VolumeSize": "40"
                        }
                    }
                ],
                "ImageId": {
                    "Ref": "BaseAmiId"
                },
                "InstanceType": "t2.micro",
                "KeyName": {
                    "Ref": "KeyName"
                },
                "NetworkInterfaces": [
                    {
                        "AssociatePublicIpAddress": "false",
                        "DeleteOnTermination": "true",
                        "DeviceIndex": "0",
                        "GroupSet": [
                            {
                                "Ref": "PrivateSecurityGroup"
                            }
                        ],
                        "PrivateIpAddress": "10.1.3.100"
                    },
                    {
                        "SubnetId": {
                            "Ref": "PrivateSubnetAZ1"
                        }
                    }
                ],
                "Tags": [
                    {
                        "Key": "Name",
                        "Value": "DC1"
                    }
                ],
                "UserData": {
                    "Fn::Base64": {
                        "Fn::Join": [
                            "",
                            [
                                "<script>\n",
                                "cfn-init.exe -v -c config -s ",
                                {
                                    "Ref": "AWS::StackId"
                                },
                                " -r DC1",
                                " --region ",
                                {
                                    "Ref": "AWS::Region"
                                },
                                "\n",
                                "</script>\n"
                            ]
                        ]
                    }
                }
            }
        }
    }
}
{
“资源”:{
“DC1”:{
“类型”:“AWS::EC2::实例”,
“财产”:{
“块设备应用程序”:[
{
“DeviceName”:“/dev/sda1”,
“Ebs”:{
“体积化”:“40”
}
}
],
“ImageId”:{
“Ref”:“baseamid”
},
“InstanceType”:“t2.micro”,
“关键字名称”:{
“Ref”:“KeyName”
},
“网络接口”:[
{
“AssociatePublicAddress”:“false”,
“DeleteOnTermination”:“true”,
“DeviceIndex”:“0”,
“组集”:[
{
“Ref”:“PrivateSecurityGroup”
}
],
“PrivateIP地址”:“10.1.3.100”
},
{
“子网”:{
“Ref”:“PrivateSubnetAZ1”
}
}
],
“标签”:[
{
“键”:“名称”,
“值”:“DC1”
}
],
“用户数据”:{
“Fn::Base64”:{
“Fn::Join”:[
"",
[
“\n”,
“cfn-init.exe-v-c config-s”,
{
“Ref”:“AWS::StackId”
},
“-r DC1”,
“--区域”,
{
“Ref”:“AWS::Region”
},
“\n”,
“\n”
]
]
}
}
}
}
}
}

您已经在网络接口中创建了json格式。因此,它正在考虑第二个问题。请尝试下面的代码片段

{
    "Resources": {
        "DC1": {
            "Type": "AWS::EC2::Instance",
            "Properties": {
                "BlockDeviceMappings": [
                    {
                        "DeviceName": "/dev/sda1",
                        "Ebs": {
                            "VolumeSize": "40"
                        }
                    }
                ],
                "ImageId": {
                    "Ref": "BaseAmiId"
                },
                "InstanceType": "t2.micro",
                "KeyName": {
                    "Ref": "KeyName"
                },
                "NetworkInterfaces": [
                    {
                        "SubnetId": {
                            "Ref": "PrivateSubnetAZ1"
                        },
                        "AssociatePublicIpAddress": "false",
                        "DeleteOnTermination": "true",
                        "DeviceIndex": "0",
                        "GroupSet": [
                            {
                                "Ref": "PrivateSecurityGroup"
                            }
                        ],
                        "PrivateIpAddress": "10.1.3.100"
                    }
                ],
                "Tags": [
                    {
                        "Key": "Name",
                        "Value": "DC1"
                    }
                ],
                "UserData": {
                    "Fn::Base64": {
                        "Fn::Join": [
                            "",
                            [
                                "<script>\n",
                                "cfn-init.exe -v -c config -s ",
                                {
                                    "Ref": "AWS::StackId"
                                },
                                " -r DC1",
                                " --region ",
                                {
                                    "Ref": "AWS::Region"
                                },
                                "\n",
                                "</script>\n"
                            ]
                        ]
                    }
                }
            }
        }
    }
}
{
“资源”:{
“DC1”:{
“类型”:“AWS::EC2::实例”,
“财产”:{
“块设备应用程序”:[
{
“DeviceName”:“/dev/sda1”,
“Ebs”:{
“体积化”:“40”
}
}
],
“ImageId”:{
“Ref”:“baseamid”
},
“InstanceType”:“t2.micro”,
“关键字名称”:{
“Ref”:“KeyName”
},
“网络接口”:[
{
“子网”:{
“Ref”:“PrivateSubnetAZ1”
},
“AssociatePublicAddress”:“false”,
“DeleteOnTermination”:“true”,
“DeviceIndex”:“0”,
“组集”:[
{
“Ref”:“PrivateSecurityGroup”
}
],
“PrivateIP地址”:“10.1.3.100”
}
],
“标签”:[
{
“键”:“名称”,
“值”:“DC1”
}
],
“用户数据”:{
“Fn::Base64”:{
“Fn::Join”:[
"",
[
“\n”,
“cfn-init.exe-v-c config-s”,
{
“Ref”:“AWS::StackId”
},
“-r DC1”,
“--区域”,
{
“Ref”:“AWS::Region”
},
“\n”,
“\n”
]
]
}
}
}
}
}
}

它将解决您在网络接口中创建json格式的问题。因此,它正在考虑第二个问题。请尝试下面的代码片段

{
    "Resources": {
        "DC1": {
            "Type": "AWS::EC2::Instance",
            "Properties": {
                "BlockDeviceMappings": [
                    {
                        "DeviceName": "/dev/sda1",
                        "Ebs": {
                            "VolumeSize": "40"
                        }
                    }
                ],
                "ImageId": {
                    "Ref": "BaseAmiId"
                },
                "InstanceType": "t2.micro",
                "KeyName": {
                    "Ref": "KeyName"
                },
                "NetworkInterfaces": [
                    {
                        "SubnetId": {
                            "Ref": "PrivateSubnetAZ1"
                        },
                        "AssociatePublicIpAddress": "false",
                        "DeleteOnTermination": "true",
                        "DeviceIndex": "0",
                        "GroupSet": [
                            {
                                "Ref": "PrivateSecurityGroup"
                            }
                        ],
                        "PrivateIpAddress": "10.1.3.100"
                    }
                ],
                "Tags": [
                    {
                        "Key": "Name",
                        "Value": "DC1"
                    }
                ],
                "UserData": {
                    "Fn::Base64": {
                        "Fn::Join": [
                            "",
                            [
                                "<script>\n",
                                "cfn-init.exe -v -c config -s ",
                                {
                                    "Ref": "AWS::StackId"
                                },
                                " -r DC1",
                                " --region ",
                                {
                                    "Ref": "AWS::Region"
                                },
                                "\n",
                                "</script>\n"
                            ]
                        ]
                    }
                }
            }
        }
    }
}
{
“资源”:{
“DC1”:{
“类型”:“AWS::EC2::实例”,
“财产”:{
“块设备应用程序”:[
{
“DeviceName”:“/dev/sda1”,
“Ebs”:{
“体积化”:“40”
}
}
],
“ImageId”:{
“Ref”:“baseamid”
},
“InstanceType”:“t2.micro”,
“关键字名称”:{
“Ref”:“KeyName”
},
“网络接口”:[
{
“子网”:{
“Ref”:“PrivateSubnetAZ1”
},
“AssociatePublicAddress”:“false”,
“DeleteOnTermination”:“true”,
“德维奇