public string AllocateAddress() { try { Amazon.EC2.Model.AllocateAddressRequest request = new Amazon.EC2.Model.AllocateAddressRequest(); Amazon.EC2.Model.AllocateAddressResponse response = ec2.AllocateAddress(request); return(response.AllocateAddressResult.PublicIp); } catch (WebException e) { throw new MonoscapeEC2Exception(e.Message, e); } catch (AmazonEC2Exception e) { throw new MonoscapeEC2Exception(e.Message, e); } }
public static void AllocateAndAssociate(string instanceId) { using (var client = new AmazonEC2Client(RegionEndpoint.USWest2)) { var allocationId = client.AllocateAddress(new AllocateAddressRequest { Domain = DomainType.Vpc }).AllocationId; Console.WriteLine("Allocation Id: " + allocationId); var associationId = client.AssociateAddress(new AssociateAddressRequest { AllocationId = allocationId, InstanceId = instanceId }).AssociationId; Console.WriteLine("Association Id: " + associationId); } }