Skip to content

Instantly share code, notes, and snippets.

@lsh-0
Created April 9, 2015 12:13
Show Gist options
  • Save lsh-0/a6304893e7f97c9f7ac4 to your computer and use it in GitHub Desktop.
Save lsh-0/a6304893e7f97c9f7ac4 to your computer and use it in GitHub Desktop.
how to attach a aws volume to an ec2 instance whilst dealing with the troublesome availability zone issue. this example is in YAML (sorry) you'll need to translate to JSON. http://stackoverflow.com/questions/20356453/is-there-a-way-to-get-a-volume-unmounted-when-i-call-cloudformation-delete-stack/25966021?noredirect=1#comment47182550_25966021
# snip
EC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId:
"Fn::FindInMap": [RegionMap, {Ref: "AWS::Region"}, AMI]
InstanceType:
"Fn::FindInMap": [RegionMap, {Ref: "AWS::Region"}, INST]
KeyName: {Ref: KeyName}
SecurityGroupIds:
-
{Ref: StackSecurityGroup}
SubnetId: subnet-foobar
Tags:
-
{Key: Name, Value: << instance_id >>}
# no good!
#Volumes:
# -
# VolumeId: {Ref: MyMount}
# Device: "/dev/sdb"
MyMount:
Type: AWS::EC2::Volume
Properties:
Size: 20 # GB
AvailabilityZone:
Fn::GetAtt: [EC2Instance, AvailabilityZone]
VolumeType: standard
MyMountPoint:
Type: AWS::EC2::VolumeAttachment
Properties:
InstanceId: {Ref: EC2Instance}
VolumeId: {Ref: MyMount}
Device: /dev/sdh
# /snip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment