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 7 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,62 @@
}
]
}
},
"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"
}
]
}
]
}
}
},
"Mappings": {
Expand Down Expand Up @@ -415,6 +471,10 @@
"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.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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
Original file line number Diff line number Diff line change
Expand Up @@ -2414,6 +2414,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
Loading