Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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 @@ -336,6 +336,56 @@
}
]
}
},
"LTWithNetworkInterfacesC793C8F4": {
"Type": "AWS::EC2::LaunchTemplate",
"Properties": {
"LaunchTemplateData": {
"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"
}
]
}
]
},
"TagSpecifications": [
{
"ResourceType": "launch-template",
"Tags": [
{
"Key": "Name",
"Value": "aws-cdk-ec2-lt-metadata-1/LTWithNetworkInterfaces"
}
]
}
]
}
}
},
"Mappings": {
Expand Down

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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ new ec2.LaunchTemplate(stack, 'LTWithPlacementGroup', {
placementGroup: pg,
});

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

Comment on lines +55 to +61
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The integration test only covers a basic case with minimal properties. It doesn't test more complex scenarios like using security groups, subnets, or other network interface properties.

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 @@ -2479,6 +2479,35 @@ const launchTemplate = new ec2.LaunchTemplate(this, 'LaunchTemplate', {
});
```

Following demonstrates how to add multiple network interface cards to launch template.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment explaining the real-world use case this example addresses, such as multi-homed instances or instances with multiple public IPs.


```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],
},
],
});
```

### Placement Group

Specify `placementGroup` to enable the placement group support:
Expand Down
Loading