AWS - 使用VPC合并云形态堆栈

时间:2018-04-02 09:23:23

标签: amazon-web-services amazon-cloudformation

我正在尝试在AWS CloudFormation中创建堆栈,我的模板基本上由Ec2实例,DB的RDS实例(MySQL引擎)和S3存储桶组成。但是,它的抛出错误说明(db.t2.micro)这个数据库实例类不能在没有VPC的情况下创建,然后我再次将数据库实例类更改为(db.m1.small)得到相同的错误。我甚至创建了一个VPC,但不确定如何在我创建的VPC中创建堆栈。我在公司的AWS账户中工作。已经很少有其他VPC可用的地方。

提前致谢:)

获得答案后修改了JSON脚本。此脚本处于工作状态,可以创建堆栈。检测过!

更新代码

    {  
    "AWSTemplateFormatVersion": "2010-09-09",   
    "Resources": {  
        "DBSubnetGroup": {  
            "Type": "AWS::RDS::DBSubnetGroup",   
            "Properties": {  
                "DBSubnetGroupDescription": "This subnet belongs to Abdul's VPC",   
                "DBSubnetGroupName": "somename",   
                "SubnetIds": [  
                    "subnet-f6b15491",   
                    "subnet-b154569e"  
                ]  
            }  
        },   
        "DB": {  
            "Type": "AWS::RDS::DBInstance",   
            "Properties": {  
                "AllocatedStorage": "5",   
                "StorageType": "gp2",   
                "DBInstanceClass": "db.m1.small",   
                "DBName": "wordpress",   
                "Engine": "MySQL",   
                "MasterUsername": "wordpress",   
                "MasterUserPassword": "Word12345",   
                "DBSubnetGroupName": {  
                    "Ref": "DBSubnetGroup"  
                }  
            }  
        },   
        "EC2": {  
            "Type": "AWS::EC2::Instance",   
            "Properties": {  
                "ImageId": "ami-c481fad3",     
                "InstanceType": "t2.micro",
                "SubnetId": "subnet-b154569e"               
            }  
        },   
        "S3": {  
            "Type": "AWS::S3::Bucket",   
            "Properties": {  
                "BucketName": "wp-abdultestbuck"  
            }  
        }  
    }  
}

1 个答案:

答案 0 :(得分:1)

您需要创建AWS::RDS::DBSubnetGroup,然后在AWS::RDS::DBInstance

中引用
  {
    "Resources": { 
        "DBSubnetGroup": {
            "Type": "AWS::RDS::DBSubnetGroup",
            "Properties": {
            "DBSubnetGroupDescription": "",
            "SubnetIds": [ "<Subnet ID 1","<Subnet ID 2>" ],
            }
        },
        "DB": {
            "Type": "AWS::RDS::DBInstance",
            "Properties": {
                ....
                "DBSubnetGroupName": { "Ref": "DBSubnetGroup" }
            }
        },
        "EC2": {
            "Type": "AWS::EC2::Instance",
            "Properties": {
              "ImageId": "ami-c481fad3",
              "InstanceType": "t2.micro",
              "SubnetId": "<SubnetID>"
            }
          }
    }
}