Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CfnEIPAssociation : Creates the association but returns an error #26423

Closed
ETisREAL opened this issue Jul 19, 2023 · 2 comments
Closed

CfnEIPAssociation : Creates the association but returns an error #26423

ETisREAL opened this issue Jul 19, 2023 · 2 comments
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@ETisREAL
Copy link

Describe the bug

I am trying to associate an EIP. This is the code:

new ec2.CfnEIPAssociation(this, `${props.STAGE}-QlashMainEIPAssociation`, {
            instanceId: qlashMain.instanceId,
            allocationId: new ec2.CfnEIP(this, `${props.STAGE}QlashMainEIP`, { instanceId: qlashMain.instanceId }).attrAllocationId
})

Expected Behavior

It should create the EIP, as I've already done before

Current Behavior

It throws this error:

12:14:19 PM | CREATE_FAILED        | AWS::EC2::EIPAssociation  | PRODQlashMainEIPAssociation
Resource handler returned message: "Resource of type 'AWS::EC2::EIPAssociation'
with identifier 'eipalloc-0daccfae170430c23' already exists." (RequestToken: fc
f075af-d0ca-f393-de91-400c74443908, HandlerErrorCode: AlreadyExists)

It is almost as if it is creating the EIP twice.

Reproduction Steps

Run the code snipped associated to any ec2 instance

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.87

Framework Version

No response

Node.js Version

v18.04

OS

Linux - Ubuntu

Language

Typescript

Language Version

No response

Other information

No response

@ETisREAL ETisREAL added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 19, 2023
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Jul 19, 2023
@ETisREAL
Copy link
Author

I figured it out myself. It is not clear in the docs, could I update it?

Anyways, if you encounter the same error, the solution is this:

Don't create EIP and EIPAssociations as you used to. ex.

 new ec2.CfnEIPAssociation(this, 'qlashMainEIPAssociation', {
            eip: new ec2.CfnEIP(this, 'qlashMainEIP', { instanceId: qlashMain.instanceId }).attrPublicIp,
            instanceId: qlashMain.instanceId
})

Don't specify the instanceId in the creation of the EIPAssociation, do it in the following manner:

new ec2.CfnEIPAssociation(this, `${props.STAGE}-QlashMainEIPAssociation`, {
            instanceId: qlashMain.instanceId,
            allocationId: new ec2.CfnEIP(this, `${props.STAGE}QlashMainEIP`, { tags: [{key: 'Name', value: `${props.STAGE}QlashMainEIP`}] }).attrAllocationId
})

just create a new CfnEIP and specify the instanceId separately.

Have a good one everybody

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant