Here is a working Amazon CloudFormation JSON template that creates an Amazon EC2 Windows 2016 instance.
I want to attach an EBS volume that is backed-up on an S3 bucket. How can I do this? Any pointers please?
{
"Parameters" :{
"KeyName" : {
"Description" : "Name of the existing EC2 KeyPair",
"Type" : "String"
}
},
"Mappings" : {
"RegionMap" : {
"us-east-1" : {
"AMI" : "ami-48b4bf31"
},
"us-west-1": {
"AMI" : "ami-48b4bf31"
},
"us-west-2":{
"AMI" : "ami-48b4bf31"
}
}
},
"Resources" : {
"Ec2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties": {
"KeyName" : {"Ref" : "KeyName"},
"ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]}
}
}
},
"Outputs" : {
"AvailablityZone" : {
"Description" : "Availability Zone of the newly created EC2 instance",
"Value" : { "Fn::GetAtt" : [ "Ec2Instance", "AvailabilityZone" ] }
},
"PublicIp" :{
"Description" : "Public IP is",
"Value": {"Fn::GetAtt": ["Ec2Instance", "PublicIp"] }
}
}
}
Backup: Your best strategy is to create an AMI on a regular basis. An AMI is a snapshot of the volumes attached to an Amazon EC2 instance -- yes, it can include ALL the disks attached to an instance. An AMI is actually just a collection of EBS snapshots, plus some metadata.
Restore: Launch a new Amazon EC2 instance from that AMI. It will contain all data, on all disks, that was present when the AMI was created. (It creates new EBS volumes, but they will contain the same data as when the AMI was created.)
Each time you create a new AMI, it will receive a new AMI-ID. Therefore, I suggest that your CloudFormation template accepts the AMI-ID as a parameter that can be entered when the stack is created. You would simply paste in the AMI-ID of the latest AMI and the instance would use that AMI.
Also, please note that AMIs are created in one region only. You can copy the AMI to a different region, but it will receive a different AMI-ID in the new region.
Frankly, your CloudFormation templates appears to be merely launching the EC2 instance, which you could do just as easily in the console without using CloudFormation.