user1951756
user1951756

Reputation: 511

Get Elastic IP from Allocation ID Parameter

I am creating a Cloudformation template that take as an input parameter the Allocation ID of and existing Elastic IP address. I have code that requires the actual IP address associated with the Allocation ID.

How do I get the IP address using the Allocation ID of EIP in the template?

If this is not possible, can we go the other way? That is, change the input parameter to the IP address of the existing EIP and somehow get the Allocation ID associated with EIP?

I require both the IP and allocation ID of the EIP within the template and I'm trying to avoid passing both in as parameters and instead determine one from the other.

Upvotes: 4

Views: 3455

Answers (1)

Miles
Miles

Reputation: 1732

If you create the EIP in another stack, you can export both the allocation ID and the IP address, and import them into your other template.

To create the EIP:

Resources:
  MyEIP:
    Type: AWS::EC2::EIP
Outputs:  
  MyEIPAllocationId:
    Value: !GetAtt MyEIP.AllocationId
    Export:
      Name: "MyEIP::AllocationId"
  MyEIPAddress:
    Value: !Ref MyEIP
    Export:
      Name: "MyEIP::Address"

Then in your other template you can use them like this:

!ImportValue MyEIP::AllocationId
!ImportValue MyEIP::Address

Upvotes: 7

Related Questions