CDK v2 issue with CfnEIPAssociation

0

Hi, After a few months of inactivity on our cdk I have tried to run it again however i have an issue with this piece of code:

        this.elasticIp = new CfnEIP(this, "euodia-managment-bastion-ip");
        new CfnEIPAssociation(this, "euodia-managment-bastion-ip-association", {
            eip: this.elasticIp.ref,
            instanceId: this.bastion.instanceId
        });

I have update my lib and changed it accordingly to:

        this.elasticIp = new CfnEIP(this, "euodia-managment-bastion-ip");
        new CfnEIPAssociation(this, "euodia-managment-bastion-ip-association", {
            allocationId: this.elasticIp.attrAllocationId,
            instanceId: this.bastion.instanceId,
        });

but when I run the cdk I have the following error:

Resource handler returned message: "resource eipalloc-0c827e3dbd214192e is already associated with associate-id eipassoc-0e2eae04c77d6069b (Service: Ec2, Status Code: 400, Request ID: 6ef0c021-9d78-46bc-9016-b8acae883a2e)" (RequestToken: bca701be-1051-881c-8c53-666c2bd04345, HandlerErrorCode: AlreadyExists)

Indeed the association already exists and should be the same as previously neither the instance, nor the elastic ip changed. Can you explain to me what is wrong plz

6 Answers
1
Accepted Answer

Thanks for your answer. I assume that in your case the SDK wants to rebuild the association according to its policy "Replacement" because eip parameter is deprecated https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-eipassociation.html but accordingly cannot do it because this association is created for this IP address. So in my opinion you can try commenting on CfnEIPAssociation after launching cdk again to detach eip from instance after that uncomment and run cdk to attach eip.

Best regards, Andrii

profile picture
EXPERT
answered 7 months ago
1

Thanks it works (but break ssh if it happend connect to the machine via aws and restart it sudo systemctl start sshd )

answered 7 months ago
1

Sure sory didn't see the option

answered 7 months ago
0

Could you please provide information on how many network interfaces has your instances? If your instance has two network interfaces, you must provide the same IP and network interface id you use in the old cdk version. // The code below shows an example of how to instantiate this type. // The values are placeholders you should change. import { aws_ec2 as ec2 } from 'aws-cdk-lib'; const cfnEIPAssociation = new ec2.CfnEIPAssociation(this, 'MyCfnEIPAssociation', /* all optional props */ { allocationId: 'allocationId', eip: 'eip', instanceId: 'instanceId', networkInterfaceId: 'networkInterfaceId', privateIpAddress: 'privateIpAddress', });

Best regards, Andrii

profile picture
EXPERT
answered 7 months ago
0

Thanks for the feedback but I just have one network interface

Enter image description here

Don't if it can be a clue but the instance is a Bastion

this.bastion = new BastionHostLinux(this, "euodia-managment-bastion", {
            vpc: this.vpc,
            instanceName: "euodia-managment-bastion",
            securityGroup: this.sg,
            subnetSelection: {
                subnetType: SubnetType.PUBLIC
            }
        });
answered 7 months ago
0

Hello. Could you please accept the answer if it helps you? Best regards, Andrii

profile picture
EXPERT
answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions