2017-12-17 19 views
0

AmazonのCloud Formationツールを使用して、Ubuntu 16.04イメージでEC2インスタンスを作成するだけです。雲の形成を使用して、地域ごとにUbuntu 16.04 EC2インスタンスを作成しますか?

これは、イメージIDがマシンの領域とアーキテクチャのタイプによって大きく異なるようであることを除けば、これは十分に簡単です。

例えば、これは、Amazonのオペレーティングシステムを実行しているEC2インスタンスを作成するには、そのランプの例で提供されるサンプルコードのごく一部です:

{ 
    "AWSTemplateFormatVersion": "2010-09-09", 
    "Parameters": { 
     "InstanceType": { 
      "Description": "WebServer EC2 instance type", 
      "Type": "String", 
      "Default": "t2.small", 
      "AllowedValues": [ 
       "t1.micro", 
       "t2.nano", 
       "t2.micro", 
       "t2.small", 
       "t2.medium", 
       "t2.large", 
       "m1.small", 
       "m1.medium", 
       "m1.large", 
       "m1.xlarge", 
       "m2.xlarge", 
       "m2.2xlarge", 
       "m2.4xlarge", 
       "m3.medium", 
       "m3.large", 
       "m3.xlarge", 
       "m3.2xlarge", 
       "m4.large", 
       "m4.xlarge", 
       "m4.2xlarge", 
       "m4.4xlarge", 
       "m4.10xlarge", 
       "c1.medium", 
       "c1.xlarge", 
       "c3.large", 
       "c3.xlarge", 
       "c3.2xlarge", 
       "c3.4xlarge", 
       "c3.8xlarge", 
       "c4.large", 
       "c4.xlarge", 
       "c4.2xlarge", 
       "c4.4xlarge", 
       "c4.8xlarge", 
       "g2.2xlarge", 
       "g2.8xlarge", 
       "r3.large", 
       "r3.xlarge", 
       "r3.2xlarge", 
       "r3.4xlarge", 
       "r3.8xlarge", 
       "i2.xlarge", 
       "i2.2xlarge", 
       "i2.4xlarge", 
       "i2.8xlarge", 
       "d2.xlarge", 
       "d2.2xlarge", 
       "d2.4xlarge", 
       "d2.8xlarge", 
       "hi1.4xlarge", 
       "hs1.8xlarge", 
       "cr1.8xlarge", 
       "cc2.8xlarge", 
       "cg1.4xlarge" 
      ], 
      "ConstraintDescription": "must be a valid EC2 instance type." 
     } 
    }, 
    "Mappings": { 
     "AWSInstanceType2Arch": { 
      "t1.micro": { 
       "Arch": "PV64" 
      }, 
      "t2.nano": { 
       "Arch": "HVM64" 
      }, 
      "t2.micro": { 
       "Arch": "HVM64" 
      }, 
      "t2.small": { 
       "Arch": "HVM64" 
      }, 
      "t2.medium": { 
       "Arch": "HVM64" 
      }, 
      "t2.large": { 
       "Arch": "HVM64" 
      }, 
      "m1.small": { 
       "Arch": "PV64" 
      }, 
      "m1.medium": { 
       "Arch": "PV64" 
      }, 
      "m1.large": { 
       "Arch": "PV64" 
      }, 
      "m1.xlarge": { 
       "Arch": "PV64" 
      }, 
      "m2.xlarge": { 
       "Arch": "PV64" 
      }, 
      "m2.2xlarge": { 
       "Arch": "PV64" 
      }, 
      "m2.4xlarge": { 
       "Arch": "PV64" 
      }, 
      "m3.medium": { 
       "Arch": "HVM64" 
      }, 
      "m3.large": { 
       "Arch": "HVM64" 
      }, 
      "m3.xlarge": { 
       "Arch": "HVM64" 
      }, 
      "m3.2xlarge": { 
       "Arch": "HVM64" 
      }, 
      "m4.large": { 
       "Arch": "HVM64" 
      }, 
      "m4.xlarge": { 
       "Arch": "HVM64" 
      }, 
      "m4.2xlarge": { 
       "Arch": "HVM64" 
      }, 
      "m4.4xlarge": { 
       "Arch": "HVM64" 
      }, 
      "m4.10xlarge": { 
       "Arch": "HVM64" 
      }, 
      "c1.medium": { 
       "Arch": "PV64" 
      }, 
      "c1.xlarge": { 
       "Arch": "PV64" 
      }, 
      "c3.large": { 
       "Arch": "HVM64" 
      }, 
      "c3.xlarge": { 
       "Arch": "HVM64" 
      }, 
      "c3.2xlarge": { 
       "Arch": "HVM64" 
      }, 
      "c3.4xlarge": { 
       "Arch": "HVM64" 
      }, 
      "c3.8xlarge": { 
       "Arch": "HVM64" 
      }, 
      "c4.large": { 
       "Arch": "HVM64" 
      }, 
      "c4.xlarge": { 
       "Arch": "HVM64" 
      }, 
      "c4.2xlarge": { 
       "Arch": "HVM64" 
      }, 
      "c4.4xlarge": { 
       "Arch": "HVM64" 
      }, 
      "c4.8xlarge": { 
       "Arch": "HVM64" 
      }, 
      "g2.2xlarge": { 
       "Arch": "HVMG2" 
      }, 
      "g2.8xlarge": { 
       "Arch": "HVMG2" 
      }, 
      "r3.large": { 
       "Arch": "HVM64" 
      }, 
      "r3.xlarge": { 
       "Arch": "HVM64" 
      }, 
      "r3.2xlarge": { 
       "Arch": "HVM64" 
      }, 
      "r3.4xlarge": { 
       "Arch": "HVM64" 
      }, 
      "r3.8xlarge": { 
       "Arch": "HVM64" 
      }, 
      "i2.xlarge": { 
       "Arch": "HVM64" 
      }, 
      "i2.2xlarge": { 
       "Arch": "HVM64" 
      }, 
      "i2.4xlarge": { 
       "Arch": "HVM64" 
      }, 
      "i2.8xlarge": { 
       "Arch": "HVM64" 
      }, 
      "d2.xlarge": { 
       "Arch": "HVM64" 
      }, 
      "d2.2xlarge": { 
       "Arch": "HVM64" 
      }, 
      "d2.4xlarge": { 
       "Arch": "HVM64" 
      }, 
      "d2.8xlarge": { 
       "Arch": "HVM64" 
      }, 
      "hi1.4xlarge": { 
       "Arch": "HVM64" 
      }, 
      "hs1.8xlarge": { 
       "Arch": "HVM64" 
      }, 
      "cr1.8xlarge": { 
       "Arch": "HVM64" 
      }, 
      "cc2.8xlarge": { 
       "Arch": "HVM64" 
      } 
     }, 
     "AWSRegionArch2AMI": { 
      "us-east-1": { 
       "PV64": "ami-2a69aa47", 
       "HVM64": "ami-6869aa05", 
       "HVMG2": "ami-1f12e965" 
      }, 
      "us-west-2": { 
       "PV64": "ami-7f77b31f", 
       "HVM64": "ami-7172b611", 
       "HVMG2": "ami-5c9b6124" 
      }, 
      "us-west-1": { 
       "PV64": "ami-a2490dc2", 
       "HVM64": "ami-31490d51", 
       "HVMG2": "ami-7291a112" 
      }, 
      "eu-west-1": { 
       "PV64": "ami-4cdd453f", 
       "HVM64": "ami-f9dd458a", 
       "HVMG2": "ami-b411c5cd" 
      }, 
      "eu-west-2": { 
       "PV64": "NOT_SUPPORTED", 
       "HVM64": "ami-886369ec", 
       "HVMG2": "NOT_SUPPORTED" 
      }, 
      "eu-central-1": { 
       "PV64": "ami-6527cf0a", 
       "HVM64": "ami-ea26ce85", 
       "HVMG2": "ami-be40f2d1" 
      }, 
      "ap-northeast-1": { 
       "PV64": "ami-3e42b65f", 
       "HVM64": "ami-374db956", 
       "HVMG2": "ami-3efd2c58" 
      }, 
      "ap-northeast-2": { 
       "PV64": "NOT_SUPPORTED", 
       "HVM64": "ami-2b408b45", 
       "HVMG2": "NOT_SUPPORTED" 
      }, 
      "ap-southeast-1": { 
       "PV64": "ami-df9e4cbc", 
       "HVM64": "ami-a59b49c6", 
       "HVMG2": "ami-3e91ed5d" 
      }, 
      "ap-southeast-2": { 
       "PV64": "ami-63351d00", 
       "HVM64": "ami-dc361ebf", 
       "HVMG2": "ami-84a142e6" 
      }, 
      "ap-south-1": { 
       "PV64": "NOT_SUPPORTED", 
       "HVM64": "ami-ffbdd790", 
       "HVMG2": "ami-25ffbe4a" 
      }, 
      "us-east-2": { 
       "PV64": "NOT_SUPPORTED", 
       "HVM64": "ami-f6035893", 
       "HVMG2": "NOT_SUPPORTED" 
      }, 
      "ca-central-1": { 
       "PV64": "NOT_SUPPORTED", 
       "HVM64": "ami-730ebd17", 
       "HVMG2": "NOT_SUPPORTED" 
      }, 
      "sa-east-1": { 
       "PV64": "ami-1ad34676", 
       "HVM64": "ami-6dd04501", 
       "HVMG2": "NOT_SUPPORTED" 
      }, 
      "cn-north-1": { 
       "PV64": "ami-77559f1a", 
       "HVM64": "ami-8e6aa0e3", 
       "HVMG2": "NOT_SUPPORTED" 
      }, 
      "cn-northwest-1": { 
       "PV64": "ami-80707be2", 
       "HVM64": "ami-cb858fa9", 
       "HVMG2": "NOT_SUPPORTED" 
      } 
     } 
    }, 
    "Resources": { 
     "WebServerInstance": { 
      "Type": "AWS::EC2::Instance", 
      "Properties": { 
       "ImageId": { 
        "Fn::FindInMap": [ 
         "AWSRegionArch2AMI", 
         { 
          "Ref": "AWS::Region" 
         }, 
         { 
          "Fn::FindInMap": [ 
           "AWSInstanceType2Arch", 
           { 
            "Ref": "InstanceType" 
           }, 
           "Arch" 
          ] 
         } 
        ] 
       }, 
       "InstanceType": { 
        "Ref": "InstanceType" 
       } 
      } 
     } 
    } 
} 

は、どのように私はUbuntuのために似た何かを行うことができます16.04? 簡単な方法はありますか?

答えて

1

Cloudformでは、Mappingsで検索できます。したがって、どの地域でも動作するスクリプトを作成するには、地域とAMI IDの間のマッピングを作成する必要があります。

list of cloud imagesからAMIのリストを取得できます。

異なるタイプのAMIを選択する必要がない場合(16.04がリストされている地域ごとに4つの異なるAMIがあります)、マップに必要なタイプを含めるか、複数の値を持つマップを作成するだけですそれがあなたが必要とするものならば。

関連する問題