2017-03-16 4 views
0

私は新しいvpc、サブネット、ec2インスタンスを作成するために使用した大きなクラウド情報jsonファイルを持っています。 基本的には、ファイルを複数の小さなファイルに分割して、簡単に保守することができます。クラウドフォーメーションファイルをより小さなスクリプトに分割する

を作成する方法a)create_vpc.jsonとvpc_param.jsonファイル。 b)aws cliからvpcのリストを取得し、vpc name/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ページでサンプルテンプレートをご覧ください。

関連する問題