Skip to content

Instantly share code, notes, and snippets.

@yhahn
Created September 21, 2016 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhahn/4fa064f063756d19d99749f9b98b7607 to your computer and use it in GitHub Desktop.
Save yhahn/4fa064f063756d19d99749f9b98b7607 to your computer and use it in GitHub Desktop.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Builds an ECS Cluster",
"Parameters": {},
"Resources": {
"SpotFleet": {
"Type": "AWS::EC2::SpotFleet",
"Properties": {
"SpotFleetRequestConfigData": {
"AllocationStrategy": "diversified",
"ExcessCapacityTerminationPolicy": "default",
"IamFleetRole": {
"Fn::GetAtt": [
"IAMFleetRole",
"Arn"
]
},
"SpotPrice": "2",
"TargetCapacity": "5",
"LaunchSpecifications": [
{
"InstanceType": "m3.xlarge",
"SecurityGroups": [],
"Monitoring": {
"Enabled": "true"
},
"ImageId": "ami-6bb2d67c",
"BlockDeviceMappings": [
{
"VirtualName": "ephemeral0",
"DeviceName": "/dev/xvdb"
},
{
"VirtualName": "ephemeral1",
"DeviceName": "/dev/xvdc"
},
{
"DeviceName": "/dev/xvdcz",
"NoDevice": true
}
],
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"\n",
[
"#!/bin/bash",
"set -ex",
"exec > >(tee /var/log/user-data.log | logger -t user-data -s 2> /dev/console) 2>&1"
]
]
}
}
}
]
}
}
},
"IAMFleetRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"spotfleet.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"Policies": [
{
"PolicyName": "fleet",
"PolicyDocument": {
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:TerminateInstances",
"ec2:RequestSpotInstances",
"ec2:DescribeImages",
"ec2:DescribeSubnets"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "iam:PassRole",
"Resource": "*"
}
]
}
}
]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment