AWS - 将 cloudformation 堆栈与 VPC 合并

AWS - Merge cloudformation stack with a VPC

我正在尝试在 AWS CloudFormation 中创建一个堆栈,我的模板基本上由 Ec2 实例、数据库的 RDS 实例(MySQL 引擎)和一个 S3 存储桶组成。但是,它的抛出错误指出 (db.t2.micro) 如果没有 VPC 则无法创建此数据库实例 class,然后我将数据库实例 class 更改为 (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"  
            }  
        }  
    }  
}

您需要创建一个 AWS::RDS::DBSubnetGroup and then reference in the 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>"
            }
          }
    }
}