My Setup :
- Three Network Interfaces
- Two EIPs attached to two network interfaces
- Associating both the EIP to the instance using network interface
I am using cloudformation and code snippet for this is below
vSRXEip11:
Type: 'AWS::EC2::EIP'
Properties:
Domain: vpc
Tags:
- Key: Name
Value: ManagementElasticIP
vSRXEip12:
Type: 'AWS::EC2::EIP'
Properties:
Domain: vpc
Tags:
- Key: Name
Value: RevenueDataElasticIP
AssociateEIP11:
Type: 'AWS::EC2::EIPAssociation'
Properties:
AllocationId: !GetAtt
- vSRXEip11
- AllocationId
NetworkInterfaceId: !Ref vSRXInterface11
AssociateEIP12:
Type: 'AWS::EC2::EIPAssociation'
Properties:
AllocationId: !GetAtt
- vSRXEip12
- AllocationId
NetworkInterfaceId: !Ref vSRXInterface12
VpcvSRXEC2Instance1:
Type: 'AWS::EC2::Instance'
Metadata:
Comment1: Launch Juniper VSRX1
Properties:
InstanceType: !FindInMap
- vSRXInstance
- !Ref VSRXType
- Type
KeyName: !Ref KeyName
DisableApiTermination: !If
- EnableTerm
- true
- false
ImageId: !FindInMap
- JunipervSRXAMI
- !Ref 'AWS::Region'
- byol
#https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-network-iface-embedded.html
NetworkInterfaces:
- NetworkInterfaceId: !Ref vSRXInterface11
DeviceIndex: '0'
- NetworkInterfaceId: !Ref vSRXInterface12
DeviceIndex: '1'
- NetworkInterfaceId: !Ref vSRXInterface13
DeviceIndex: '2'
Tags:
- Key: Name
Value: Juniper VSRX1
DependsOn: IGW
When I deploy above cloudformation template, I see sometimes vSRXEip11
attached as public IP and sometimes vSRXEip12
.
How should I make the public IP address of EC2 instance to either vSRXEip11
or vSRXEip12
?
I tried with associatePublicIPAddress
for one of the network interface like below.
VpcvSRXEC2Instance1:
Type: 'AWS::EC2::Instance'
Metadata:
Comment1: Launch Juniper VSRX1
Properties:
InstanceType: !FindInMap
- vSRXInstance
- !Ref VSRXType
- Type
KeyName: !Ref KeyName
DisableApiTermination: !If
- EnableTerm
- true
- false
ImageId: !FindInMap
- JunipervSRXAMI
- !Ref 'AWS::Region'
- byol
#https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-network-iface-embedded.html
NetworkInterfaces:
- NetworkInterfaceId: !Ref vSRXInterface11
DeviceIndex: '0'
AssociatePublicIPAddress: true
- NetworkInterfaceId: !Ref vSRXInterface12
DeviceIndex: '1'
- NetworkInterfaceId: !Ref vSRXInterface13
DeviceIndex: '2'
But got an error saying "The associatePublicIPAddress parameter cannot be specified when launching with multiple network interfaces"