2017-03-16 35 views
0

我有大型的cloudformation json文件,我用它來創建新的vpc,子網,ec2實例。 基本上打破文件分成多個小文件,以方便維護。將雲信息文件分解爲更小的腳本

如何創建 a)create_vpc.json和vpc_param.json文件。 b)如何從aws cli獲取vpc列表並將vpc名稱/ id傳遞給create_subnet.json並定義subnet_param.json。 c)使用aws cli獲取vpc的子網列表,並將其作爲參數傳遞給create_routetable.json和routetable_param.json。

同樣想要爲ec2/elb /其他東西創建其他腳本。

aws cloudformation create-stack --stackname startmyinstance --template-body file:///some/local/path/templates/startmyinstance.json --parameters file:///some/local/path/params/startmyinstance-parameters.json 

我的當前文件是:

{ 
    "AWSTemplateFormatVersion": "2010-09-09", 
    "Description": " Tempalte to launch Custom VPC with two availablilty zones. **WARNING** This template might create one or more Amazon EC2 instances. You will be billed for the AWS resources used if you create a stack from this template.", 
    "Parameters": { 
     "KeyName": { 
     "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instances", 
     "Type": "String", 
     "MinLength": "1", 
     "MaxLength": "64", 
     "AllowedPattern": "[-_ a-zA-Z0-9]*", 
     "Default": "Helix-PROD", 
     "ConstraintDescription": "can contain only alphanumeric characters, spaces, dashes and underscores." 
     }, 
     "VpcCidr": { 
     "Description": "CIDR address for the VPC to be created.", 
     "Type": "String", 
     "Default": "10.206.36.0/22" 
     }, 
     "SUB1": { 
     "Description": "subnet1.", 
     "Type": "String", 
     "Default": "10.206.36.0/27" 
     }, 
     "SUB2": { 
     "Description": "subnet2", 
     "Type": "String", 
     "Default": "10.206.36.32/27" 
     }, 

     "AvailabilityZone1": { 
     "Description": "First AZ to use for Public1/private1 subnets.", 
     "Type": "AWS::EC2::AvailabilityZone::Name", 
     "Default": "eu-west-1a" 
     }, 
     "AvailabilityZone2": { 
     "Description": "First AZ to use for Public2/private2 subnets.", 
     "Type": "AWS::EC2::AvailabilityZone::Name", 
     "Default": "eu-west-1b" 
     }, 
    }, 
    "Mappings": { 
     "RegionMap": { 

     "eu-west-1": { 
      "64": "ami-70edb016" 
     } 
     } 

    }, 

    "Resources": { 
     "VPC": { 
     "Type": "AWS::EC2::VPC", 
     "Properties": { 
      "CidrBlock": { 
       "Ref": "VpcCidr" 
      }, 
      "Tags": [{ 
       "Key": "Network", 
       "Value": "Public" 
      }] 
     } 
     }, 
     "Sub1": { 
     "Type": "AWS::EC2::Subnet", 
     "Properties": { 
      "VpcId": { 
       "Ref": "VPC" 
      }, 
      "AvailabilityZone": { 
       "Ref": "AvailabilityZone1" 
      }, 
      "CidrBlock": { 
       "Ref": "subnet1" 
      }, 
      "Tags": [{ 
       "Key": "Network", 
       "Value": "Private" 
      }, { 
       "Key": "Name", 
       "Value": "Sub1" 
      }] 
     } 
     }, 
     "Sub2": { 
     "Type": "AWS::EC2::Subnet", 
     "Properties": { 
      "VpcId": { 
       "Ref": "VPC" 
      }, 
      "AvailabilityZone": { 
       "Ref": "AvailabilityZone2" 
      }, 
      "CidrBlock": { 
       "Ref": "subnet2" 
      }, 
      "Tags": [{ 
       "Key": "Network", 
       "Value": "Private" 
      }, { 
       "Key": "Name", 
       "Value": "Sub2" 
      }] 
     } 
     }, 
    } 
} 

回答

0

你可以使用Nested Stacks - (此鏈接解釋它們是什麼或什麼時候使用)。如果您想查看示例模板或摘錄,請訪問this AWS頁面以查看示例模板。

相關問題