Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 735
user1951756 Avatar asked Sep 13 '25 12:09

user1951756


1 Answers

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
like image 192
Miles Avatar answered Sep 15 '25 03:09

Miles