ec2: deprecation warning when using `ec2.BastionHostLinux` with default values.
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
A warning will be generated if use the default values due to the use of a deprecated API in `ec2.BastionHostLinux`.
```
console.warn
[WARNING] aws-cdk-lib.aws_ec2.MachineImage#latestAmazonLinux is deprecated.
use MachineImage.latestAmazonLinux2 instead
This API will be removed in the next major release.
8 | const vpc = new cdk.aws_ec2.Vpc(this, "Vpc");
9 |
> 10 | new cdk.aws_ec2.BastionHostLinux(this, "BastionHost", {
| ^
11 | vpc: vpc,
12 | });
13 | }
at Object.print (node_modules/aws-cdk-lib/.warnings.jsii.js:83646:21)
at Function.latestAmazonLinux (node_modules/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.js:139:37)
at new BastionHostLinux (node_modules/aws-cdk-lib/aws-ec2/lib/bastion-host.ts:183:56)
at new SandboxCdkStack (lib/sandbox-cdk-stack.ts:10:5)
at Object. (test/sandbox-cdk.test.ts:9:17)
```
### Expected Behavior
No warnings should be displayed.
### Current Behavior
The following message is displayed:
```
aws-cdk-lib.aws_ec2.MachineImage#latestAmazonLinux is deprecated.
Use MachineImage.latestAmazonLinux2 instead
This API will be removed in the next major release.
```
### Reproduction Steps
```typescript
import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";
export class SandboxCdkStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc = new cdk.aws_ec2.Vpc(this, "Vpc");
new cdk.aws_ec2.BastionHostLinux(this, "BastionHost", {
vpc: vpc,
});
}
}
```
### Possible Solution
Explicitly pass the `machineImage` argument.
### Additional Information/Context
_No response_
### CDK CLI Version
2.76.0
### Framework Version
_No response_
### Node.js Version
v18.14.2
### OS
macOS
### Language
Typescript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Start in aws-ec2/lib/bastion-host.ts, focusing on the BastionHostLinux constructor path used when no machineImage is supplied. Reproduce the warning with the example in test/sandbox-cdk.test.ts, then verify the default path no longer emits the deprecation warning and the test still passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- infrastructure
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100