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

feat(ec2): network interface definitions for launch templates #29875

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -265,13 +265,73 @@
}
]
}
},
"LTWithNetworkInterfacesC793C8F4": {
"Type": "AWS::EC2::LaunchTemplate",
"Properties": {
"LaunchTemplateData": {
"ImageId": {
"Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestal2023amikernel61x8664C96584B6F00A464EAD1953AFF4B05118Parameter"
},
"NetworkInterfaces": [
{
"AssociatePublicIpAddress": false,
"DeleteOnTermination": true,
"DeviceIndex": 0
},
{
"AssociatePublicIpAddress": false,
"DeleteOnTermination": true,
"DeviceIndex": 1
}
],
"TagSpecifications": [
{
"ResourceType": "instance",
"Tags": [
{
"Key": "Name",
"Value": "aws-cdk-ec2-lt-metadata-1/LTWithNetworkInterfaces"
}
]
},
{
"ResourceType": "volume",
"Tags": [
{
"Key": "Name",
"Value": "aws-cdk-ec2-lt-metadata-1/LTWithNetworkInterfaces"
}
]
}
],
"UserData": {
"Fn::Base64": "#!/bin/bash"
}
},
"TagSpecifications": [
{
"ResourceType": "launch-template",
"Tags": [
{
"Key": "Name",
"Value": "aws-cdk-ec2-lt-metadata-1/LTWithNetworkInterfaces"
}
]
}
]
}
}
},
"Parameters": {
"SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter": {
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
"Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"
},
"SsmParameterValueawsserviceamiamazonlinuxlatestal2023amikernel61x8664C96584B6F00A464EAD1953AFF4B05118Parameter": {
"Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
"Default": "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64"
},
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -36,6 +36,14 @@ new ec2.LaunchTemplate(stack, 'LTWithMachineImage', {
}),
});

new ec2.LaunchTemplate(stack, 'LTWithNetworkInterfaces', {
machineImage: ec2.MachineImage.latestAmazonLinux2023(),
networkInterfaces: [
{ associatePublicIpAddress: false, deviceIndex: 0, deleteOnTermination: true },
{ associatePublicIpAddress: false, deviceIndex: 1, deleteOnTermination: true },
],
});

new integ.IntegTest(app, 'LambdaTest', {
testCases: [stack],
diffAssets: true,
Expand Down
29 changes: 29 additions & 0 deletions packages/aws-cdk-lib/aws-ec2/README.md
Expand Up @@ -2235,6 +2235,35 @@ const launchTemplate = new ec2.LaunchTemplate(this, 'LaunchTemplate', {
});
```

Following demonstrates how to add multiple network interface cards to launch template.

```ts
declare const vpc: ec2.Vpc;

const sg1 = new ec2.SecurityGroup(this, 'sg1', {
vpc: vpc,
});
const sg2 = new ec2.SecurityGroup(this, 'sg2', {
vpc: vpc,
});

new ec2.LaunchTemplate(this, 'LaunchTemplate', {
machineImage: ec2.MachineImage.latestAmazonLinux2023(),
networkInterfaces: [
{
associatePublicIpAddress: false,
deviceIndex: 0,
groups: [sg1],
},
{
associatePublicIpAddress: false,
deviceIndex: 1,
groups: [sg2],
},
],
});
```

Please note this feature does not support Launch Configurations.

## Detailed Monitoring
Expand Down