Skip to content

Instantly share code, notes, and snippets.

@masayang
Created December 12, 2012 06:33
Show Gist options
  • Save masayang/4265541 to your computer and use it in GitHub Desktop.
Save masayang/4265541 to your computer and use it in GitHub Desktop.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Create a Server in specified VPC subnet",
"Parameters": {
"InstanceType": {
"Description": "EC2 instance type",
"Type": "String",
"Default": "t1.micro",
"AllowedValues": [
"m1.small",
"t1.micro"
]
},
"KeyPair": {
"Description": "Your KeyPair Name",
"Type": "String",
"Default": "your_name_here"
},
"SubnetId": {
"Description": "This server's subnet in subnet-xxxxxx format",
"Type": "String",
"Default": "subnet-xxxxxx"
},
"SecurityGroupIds": {
"Description": "This server's security group",
"Type": "String",
"Default": "sg-xxxxxxxx"
},
"ServerName": {
"Description": "This server's tag name",
"Type": "String",
"Default": "test bastion"
}
},
"Mappings": {
"AWSInstanceType2Arch": {
"m1.small": {
"Arch": "64"
},
"t1.micro": {
"Arch": "64"
}
},
"AWSRegionArch2AMI": {
"ap-northeast-1": {
"64": "ami-4e6cd34f"
}
}
},
"Resources": {
"IPAddress": {
"Type": "AWS::EC2::EIP",
"Properties": {
"Domain": "vpc",
"InstanceId": {
"Ref": "Instance"
}
}
},
"WaitHandle": {
"Type": "AWS::CloudFormation::WaitConditionHandle"
},
"Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"InstanceType": {
"Ref": "InstanceType"
},
"ImageId": {
"Fn::FindInMap": [
"AWSRegionArch2AMI",
{
"Ref": "AWS::Region"
},
{
"Fn::FindInMap": [
"AWSInstanceType2Arch",
{
"Ref": "InstanceType"
},
"Arch"
]
}
]
},
"KeyName": {
"Ref": "KeyPair"
},
"SubnetId": {
"Ref": "SubnetId"
},
"Tags": [
{
"Key": "Name",
"Value": {
"Ref": "ServerName"
}
}
],
"SecurityGroupIds": [
{
"Ref": "SecurityGroupIds"
}
],
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash -v\n",
"yum update -y aws-cfn-bootstrap\n",
"# Helper function\n",
"function error_exit\n",
"{\n",
" /opt/aws/bin/cfn-signal -e 0 -r \"$1\" '",
{
"Ref": "WaitHandle"
},
"'\n",
" exit 1\n",
"}\n",
"# Install Stuff through yum\n",
"yum update -y\n",
"# All is well so signal success\n",
"/opt/aws/bin/cfn-signal -e 0 -r \"server setup complete\" '",
{
"Ref": "WaitHandle"
},
"'\n"
]
]
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment