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

(aws-ec2): Need to be able to freely configure network interfaces in L2 LaunchTemplate #30891

Open
1 of 2 tasks
chenhe95 opened this issue Jul 18, 2024 · 9 comments
Open
1 of 2 tasks
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud @aws-cdk/custom-resources Related to AWS CDK Custom Resources effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@chenhe95
Copy link

chenhe95 commented Jul 18, 2024

Describe the feature

I'd like it if I could be able to just pass in the networkInterfaces to the underlying L1 construct from the L2 constructor, instead of the L2 construct creating the networkInterfaces for me, which doesn't have all of the things I'd like to put in.

The current launch template behavior of deciding the network interface doesn't really work for me https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-ec2/lib/launch-template.ts#L734-L736

    const networkInterfaces = props.associatePublicIpAddress !== undefined
      ? [{ deviceIndex: 0, associatePublicIpAddress: props.associatePublicIpAddress, groups: securityGroupsToken }]
      : undefined;

Use Case

To not be limited to only network interfaces with a device index of 0 with a configured associatePublicIpAddress. To be able to use the entirety of NetworkInterfaceProperty for my L2 LaunchTemplate construct

Proposed Solution

Change the LaunchTemplate behavior as follows

  1. Add an optional networkInterfaces? field to the LaunchTemplateProps, same as the L1 version
  2. If networkInterfaces is provided, do not create the network interfaces on this line
    const networkInterfaces = props.associatePublicIpAddress !== undefined
      ? [{ deviceIndex: 0, associatePublicIpAddress: props.associatePublicIpAddress, groups: securityGroupsToken }]
      : undefined;

And also do not create the securityGroupsToken

    const securityGroupsToken = Lazy.list({
      produce: () => {
        if (this._connections && this._connections.securityGroups.length > 0) {
          return this._connections.securityGroups.map(sg => sg.securityGroupId);
        }
        return undefined;
      },
    });

And also pass in the provided props networkInterfaces to CfnLaunchTemplate and pass in undefined to securityGroupIds
3. If associatePublicIpAddress is provided through the props but networkInterfaces is not provided through props, retain the current behavior as if associatePublicIpAddress is provided.
4. If neither are provided through props, retain the current behavior as if associatePublicIpAddress is not provided
5. If both associatePublicIpAddress and networkInterfaces are provided through props, then there is a conflict as there are 2 sources of truth. We could throw an error throw new Error('You cannot provide both a networkInterfaces and an associatePublicIpAddress');

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

1.148.0

Environment details (OS name and version, etc.)

Mac OS Sonoma 14.5

@chenhe95 chenhe95 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jul 18, 2024
@github-actions github-actions bot added the @aws-cdk/custom-resources Related to AWS CDK Custom Resources label Jul 18, 2024
@chenhe95
Copy link
Author

Something I just realized is that there might not be a L2 abstraction for the launch template network interfaces https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-networkinterface.html

Note: This is different than EC2 network interfaces https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-networkinterface.html

@chenhe95 chenhe95 changed the title L2 LaunchTemplate: Need to be able to freely configure network interfaces (aws-ec2): Need to be able to freely configure network interfaces in L2 LaunchTemplate Jul 19, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Jul 19, 2024
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Jul 19, 2024
@khushail khushail self-assigned this Jul 19, 2024
@khushail
Copy link
Contributor

khushail commented Jul 19, 2024

Hi @chenhe95 ,thanks for reaching out.

You could always use the Escape hatches to pass the desired properties to Cloudformation L1 construct directly,you could use CfnInstance and set the netowrkinterface the way you would like.

Please let me know if that would solve your usecase. If it doesn't, and you would still like to propose a L2 construct, we have a set procedure for that. You would have to submit an RFC and get the approval on design and after review and acceptance by the Core team, you could proceed with contribution. However this whole contribution process is currently under review and being reassessed. Please feel free to check this ReadMe on L2 construct submission..
Hope that helps!

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Jul 19, 2024
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jul 21, 2024
@chenhe95
Copy link
Author

Thanks, I'll look into the L2 construct submission

@chenhe95
Copy link
Author

@khushail Is this actually a L2 construct or is this just a regular typescript interface to satisfy the expected params of a L1 construct?
My understanding is that the data structure needed for LaunchTemplate's NetworkInterface is not actually anything that extends, uses, or relates to the actual class Construct but would be more of an interface like

/**
 * Interface for the Spot market instance options provided in a LaunchTemplate.
 */
export interface LaunchTemplateSpotOptions {
  /**
   * Spot Instances with a defined duration (also known as Spot blocks) are designed not to be interrupted and will run continuously for the duration you select.
   * You can use a duration of 1, 2, 3, 4, 5, or 6 hours.
   *
   * @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-requests.html#fixed-duration-spot-instances
   *
   * @default Requested spot instances do not have a pre-defined duration.
   */
  readonly blockDuration?: Duration;

  /**
   * The behavior when a Spot Instance is interrupted.
   *
   * @default Spot instances will terminate when interrupted.
   */
  readonly interruptionBehavior?: SpotInstanceInterruption;

  /**
   * Maximum hourly price you're willing to pay for each Spot instance. The value is given
   * in dollars. ex: 0.01 for 1 cent per hour, or 0.001 for one-tenth of a cent per hour.
   *
   * @default Maximum hourly price will default to the on-demand price for the instance type.
   */
  readonly maxPrice?: number;

  /**
   * The Spot Instance request type.
   *
   * If you are using Spot Instances with an Auto Scaling group, use one-time requests, as the
   * Amazon EC2 Auto Scaling service handles requesting new Spot Instances whenever the group is
   * below its desired capacity.
   *
   * @default One-time spot request.
   */
  readonly requestType?: SpotRequestType;

  /**
   * The end date of the request. For a one-time request, the request remains active until all instances
   * launch, the request is canceled, or this date is reached. If the request is persistent, it remains
   * active until it is canceled or this date and time is reached.
   *
   * @default The default end date is 7 days from the current date.
   */
  readonly validUntil?: Expiration;
};

@chenhe95
Copy link
Author

I'm reading through the RFC documents and the LaunchTemplate NetworkInterface doesn't seem to actually match the definition of a L2 construct

The next level of constructs, L2, also represent AWS resources, but with a
higher-level, intent-based API. They provide similar functionality, but provide
the defaults, boilerplate, and glue logic you'd be writing yourself with a CFN
Resource construct. L2 constructs offer convenient defaults and reduce the need
to know all the details about the AWS resources they represent, while providing
convenience methods that make it simpler to work with the resource. For example,
the `s3.Bucket` class represents an Amazon S3 bucket with additional properties
and methods, such as `bucket.addLifeCycleRule()`, which adds a lifecycle rule to
the bucket.
because the launch template network interface does not actually represent an AWS resource and only represents the formatting an input parameter for an AWS L1 resource

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jul 22, 2024
@chenhe95
Copy link
Author

Would LaunchTemplateNetworkInterfaceOptions be a good name for this network interface abstraction? Or is that too verbose?

@khushail
Copy link
Contributor

khushail commented Jul 23, 2024

@chenhe95 , found a PR for the same -#29875 and another one having overlapping concepts - #28901, Could you confirm if this PR addresses your request.

@khushail khushail added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 23, 2024
@chenhe95
Copy link
Author

Thanks! #29875 basically solves my issue if it would be merged

@khushail khushail added p2 effort/medium Medium work item – several days of effort and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jul 24, 2024
@khushail khushail removed their assignment Jul 24, 2024
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 @aws-cdk/custom-resources Related to AWS CDK Custom Resources effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

2 participants