-
Notifications
You must be signed in to change notification settings - Fork 4k
/
bottlerocket.ts
44 lines (38 loc) · 1.17 KB
/
bottlerocket.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ssm from '@aws-cdk/aws-ssm';
import { Construct } from '@aws-cdk/core';
/**
* Properties for BottleRocketImage
*/
export interface BottleRocketImageProps {
/**
* The Kubernetes version to use
*/
readonly kubernetesVersion: string;
}
/**
* Construct an Bottlerocket image from the latest AMI published in SSM
*/
export class BottleRocketImage implements ec2.IMachineImage {
private readonly kubernetesVersion: string;
private readonly amiParameterName: string;
/**
* Constructs a new instance of the BottleRocketImage class.
*/
public constructor(props: BottleRocketImageProps) {
this.kubernetesVersion = props.kubernetesVersion;
// set the SSM parameter name
this.amiParameterName = `/aws/service/bottlerocket/aws-k8s-${this.kubernetesVersion}/x86_64/latest/image_id`;
}
/**
* Return the correct image
*/
public getImage(scope: Construct): ec2.MachineImageConfig {
const ami = ssm.StringParameter.valueForStringParameter(scope, this.amiParameterName);
return {
imageId: ami,
osType: ec2.OperatingSystemType.LINUX,
userData: ec2.UserData.custom(''),
};
}
}