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

标签 json amazon-web-services amazon-ec2 aws-cloudformation

我一直在尝试让两个实例加入域,其中一个是 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"
                            ]
                        ]
                    }
                }
            }
        }
    }
}

最佳答案

您已在网络接口(interface)中创建了 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"
                            ]
                        ]
                    }
                }
            }
        }
    }
}

它将解决问题

关于json - 云形成 - 设备索引不能为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50197548/

相关文章:

javascript - D3.js:使用强制布局从 JSON 文件加载多个网络

amazon-web-services - AWS Lambda 上没有有效负载属性调用 CLI 响应

amazon-web-services - AWS CodeDeploy 部署跟踪

json - jq:当数组中有任何值时选择

Java 客户端到 Spring Data Rest 服务器

javascript - 将 HTML 表单数据转换为嵌套 JSON

amazon-web-services - 不存在的导出/输出阻止堆栈更新/删除

php - MySQL 连接无法在 AWS EC2 上运行

amazon-ec2 - EC2 : Connecting to own mysql server on external address

amazon-web-services - 作为一个实验,我想与 AWS 一起工作。我期望支付多少?