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); } }
public void AssociateAddress(string vmInstanceId, string ipAddress) { try { AWSModel.AssociateAddressRequest request = new AWSModel.AssociateAddressRequest(); request.InstanceId = vmInstanceId; request.PublicIp = ipAddress; ec2.AssociateAddress(request); } catch (WebException e) { throw new MonoscapeEC2Exception(e.Message, e); } catch (AmazonEC2Exception e) { throw new MonoscapeEC2Exception(e.Message, e); } catch (XmlException e) { // There is an issue in Amazon EC2 API in processing the XML returned from euca_associate_address, // still the remote call has executed properly. Ignore the xml exception as an workaround Log.Debug(this, "AssociateAddress() XmlException raised", e); } }