My company want to take daily snapshots of a windows in Amazon Web Service. We can take snapshot without any issue but when I try to create instance from snapshot, it always cr
[Please note that I'm assuming you are using EBS-Backed EC2 instances; if not, please check Eric Hammond's explanation why You Should Use EBS Boot Instances on Amazon EC2.]
It sounds like there might be a misunderstanding regarding the related AWS concepts:
While Amazon EBS snapshots are indeed utilized for the creation of an Amazon Machine Images (AMI) under the hood, you do not explicitly interact with them for the use case at hand. Specifically, you don't want to use CreateSnapshot, which only Creates a snapshot of an Amazon EBS volume and stores it in Amazon S3, rather you want to simply create such an AMI via the dedicated action CreateImage, which Creates an Amazon EBS-backed AMI from an Amazon EBS-backed instance that is either running or stopped [emphasis mine]:
Once you have an image (AMI) generated like so in place, creating your Amazon EC2 instance from that AMI should work out as desired, be it a Windows or Unix one.
try this
var launchRequest = new RunInstancesRequest()
{
ImageId = amiID,
InstanceType = ConfigurationManager.AppSettings["AwsInstanceType"],
MinCount = 1,
MaxCount = 1,
KeyName = keyPairName,
SecurityGroupIds = groups,
SubnetId = ConfigurationManager.AppSettings["AwsSubnetId"],
};
RunInstancesResponse runInstancesResponse = amazonEc2client.RunInstances(launchRequest);
var InstanceId = runInstancesResponse.Reservation.Instances[0].InstanceId;
var trequest = new CreateTagsRequest();
trequest.Resources=new List<string>(){InstanceId};
List<Tag> tags=new List<Tag>();
Tag tag=new Tag("Name","TestCodeFinal");
tags.Add(tag);
trequest.Tags = tags;
amazonEc2client.CreateTags(trequest);
Reservation reservation = runInstancesResponse.Reservation;