How to create a windows instance from snapshot in AWS

后端 未结 2 802
渐次进展
渐次进展 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: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(){InstanceId};
                    List tags=new List();
                    Tag tag=new Tag("Name","TestCodeFinal");
                    tags.Add(tag);
                    trequest.Tags = tags;
                    amazonEc2client.CreateTags(trequest);
                    Reservation reservation = runInstancesResponse.Reservation;
    

提交回复
热议问题