aws-ec2: Support creating CfnNetworkInterface without specifying subnet in CDK #24964
Closed
2 tasks
Labels
@aws-cdk/aws-ec2
Related to Amazon Elastic Compute Cloud
feature-request
A feature should be added or improved.
p2
response-requested
Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Describe the feature
Unsure if this is actually a valid feature request, or just an inquiry on possible solutions for the use case
Today CfnNetworkInterface requires you to enter a subnetId in CfnNetworkInterfaceProps, can we make it so that subnetId is not a required field but something else such as availability zone.
Use Case
The AWS CLI provides an option to configure a LaunchTemplate specifying an existing network interface as the primary network interface for an autoscaling group.
https://docs.aws.amazon.com/autoscaling/ec2/userguide/examples-launch-templates-aws-cli.html#example-existing-eni-launch-template
This is not possible easily in CDK today through L2 construct LaunchTemplate: #14494
For ENI defined through cdk through L1 construct, CfnNetworkInterface, public subnet must be defined.
We can create a LaunchTemplate with an existing ENI through to CfnLaunchTemplate in networkinterfaces
However when passing this into an cfnAutoScalingGroup, cloudformation has this error:
Wish to be able to configure instances mapped to an ENI with an ASG through CDK.
Proposed Solution
it looks like this is possible through cli, https://docs.aws.amazon.com/autoscaling/ec2/userguide/examples-launch-templates-aws-cli.html#example-existing-eni-launch-template
Here the region is probably configured through aws-cli, even when creating the network interface but unsure.
Wondering if having alternative to creating network interface other than subnet would work, if this is something that is able to be solved through CDK, or if this is not possible if this is happening on server side or through some cloudformation.
Other Information
Some workaround I have tried:
The stack is able to deploy without error when specifying subnetId instead of NetworkInterface id:
This is just a quick hack though and not ideal, since it creates a bunch of useless resources in cloudformation, although that is probably able to be solved just by using all L1 constructs.
However, when the instance gets terminated/restarted, the ASG will create a new network interface instead of using the one created at deployment, for now I just set min, max, desired all to 1.
Acknowledgements
CDK version used
2.70.0
Environment details (OS name and version, etc.)
Typescript, AL2
The text was updated successfully, but these errors were encountered: