How to create a windows instance from snapshot in AWS

后端 未结 2 800
渐次进展
渐次进展 2021-02-06 08:14

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

相关标签:
2条回答
  • 2021-02-06 08:25

    [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]:

    • This process is outlined in Creating Amazon EBS-Backed AMIs (while this section addresses creating a 'new' AMI, the process is identical to your backup scenario).
    • Please note that CreateImage automatically takes care of additional EBS volumes attached to your instance as well, if any:
      • If you customized your instance with instance store volumes or EBS volumes in addition to the root device volume, the new AMI contains block device mapping information for those volumes. When you launch an instance from this new AMI, the instance automatically launches with those additional volumes.

    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.

    0 讨论(0)
  • 2021-02-06 08:33

    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;
    
    0 讨论(0)
提交回复
热议问题