2017-03-16 26 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页面以查看示例模板。

相关问题