I currently have my template here which is to allocate an EIP for my instance. (Last part)
However, I would wish to use my fixed EIP instead of relying on CloudFormation randomly generating a new EIP everytime.
Resources:
EC2Example:
Type: "AWS::EC2::Instance"
Metadata:
AWS::CloudFormation::Init:
services:
sysvint:
codedeploy-agent:
enabled: 'true'
ensureRunning: 'true'
Properties:
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
KeyName: !Ref SSHKeyName
IamInstanceProfile: "EC2CodeDeploy"
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0"
GroupSet:
- Ref: "SecurityGroupIds"
SubnetId:
Ref: "PrivateSubnet"
BlockDeviceMappings:
-
DeviceName: /dev/sda1
Ebs:
VolumeType: io1
Iops: !Ref IOPS
DeleteOnTermination: false
VolumeSize: !Ref VolumeSize
ElasticIP:
Type: AWS::EC2::EIP
Properties:
Domain: vpc
InstanceId: !Ref EC2Example
CodePudding user response:
You have to use AWS::EC2::EIPAssociation. In your case:
AssociateControlPort:
Type: AWS::EC2::EIPAssociation
Properties:
AllocationId: !GetAtt ElasticIP.AllocationId
InstanceId: !Ref EC2Example