AmazonLinuxImage Class
Selects the latest version of Amazon Linux.
This Machine Image automatically updates to the latest version on every deployment. Be aware this will cause your instances to be replaced when a new version of the image becomes available. Do not store stateful information on the instance if you are using this image.
The AMI ID is selected using the values published to the SSM parameter store.
Example
ts
declare const vpc: ec2.IVpc;
const lb = new elb.LoadBalancer(this, 'LB', {
vpc,
internetFacing: true,
});
// instance to add as the target for load balancer.
const instance = new ec2.Instance(this, 'targetInstance', {
vpc: vpc,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
machineImage: new ec2.AmazonLinuxImage({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 }),
});
lb.addTarget(new elb.InstanceTarget(instance));
python
# vpc: ec2.IVpc
lb = elb.LoadBalancer(self, "LB",
vpc=vpc,
internet_facing=True
)
# instance to add as the target for load balancer.
instance = ec2.Instance(self, "targetInstance",
vpc=vpc,
instance_type=ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
machine_image=ec2.AmazonLinuxImage(generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2)
)
lb.add_target(elb.InstanceTarget(instance))
java
IVpc vpc;
LoadBalancer lb = LoadBalancer.Builder.create(this, "LB")
.vpc(vpc)
.internetFacing(true)
.build();
// instance to add as the target for load balancer.
Instance instance = Instance.Builder.create(this, "targetInstance")
.vpc(vpc)
.instanceType(InstanceType.of(InstanceClass.BURSTABLE2, InstanceSize.MICRO))
.machineImage(AmazonLinuxImage.Builder.create().generation(AmazonLinuxGeneration.AMAZON_LINUX_2).build())
.build();
lb.addTarget(new InstanceTarget(instance));
csharp
// Install: dotnet add package Amazon.CDK.Lib
IVpc vpc;
var lb = new LoadBalancer(this, "LB", new LoadBalancerProps {
Vpc = vpc,
InternetFacing = true
});
// instance to add as the target for load balancer.
var instance = new Instance(this, "targetInstance", new InstanceProps {
Vpc = vpc,
InstanceType = InstanceType.Of(InstanceClass.BURSTABLE2, InstanceSize.MICRO),
MachineImage = new AmazonLinuxImage(new AmazonLinuxImageProps { Generation = AmazonLinuxGeneration.AMAZON_LINUX_2 })
});
lb.AddTarget(new InstanceTarget(instance));
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc IVpc
lb := elb.NewLoadBalancer(this, jsii.String("LB"), &LoadBalancerProps{
Vpc: Vpc,
InternetFacing: jsii.Boolean(true),
})
// instance to add as the target for load balancer.
instance := ec2.NewInstance(this, jsii.String("targetInstance"), &InstanceProps{
Vpc: vpc,
InstanceType: ec2.InstanceType_Of(ec2.InstanceClass_BURSTABLE2, ec2.InstanceSize_MICRO),
MachineImage: ec2.NewAmazonLinuxImage(&AmazonLinuxImageProps{
Generation: ec2.AmazonLinuxGeneration_AMAZON_LINUX_2,
}),
})
lb.AddTarget(elb.NewInstanceTarget(instance))
Initializer
ts
new AmazonLinuxImage(props?: AmazonLinuxImageProps)
python
AmazonLinuxImage(props: typing.Optional[AmazonLinuxImageProps] = None)
java
new AmazonLinuxImage(AmazonLinuxImageProps props)
csharp
new AmazonLinuxImage(AmazonLinuxImageProps? props = null)
go
NewAmazonLinuxImage(Props AmazonLinuxImageProps)
Properties
parameterNamestringparameter_namestrparameterNameStringParameterNamestringParameterName*stringrequired#Name of the SSM parameter we're looking up.
Methods
getImage(scope: Construct): MachineImageConfigdef get_image(self, scope: Construct) -> MachineImageConfigpublic MachineImageConfig getImage(Construct scope)public MachineImageConfig GetImage(Construct scope)func GetImage(Scope Construct) MachineImageConfig#Return the image to use in the given context.
ssmParameterName(props?: AmazonLinuxImageProps): string@staticmethod def ssm_parameter_name(props: typing.Optional[AmazonLinuxImageProps] = None) -> strpublic static String ssmParameterName(AmazonLinuxImageProps props)public static string SsmParameterName(AmazonLinuxImageProps? props = null)func SsmParameterName(Props AmazonLinuxImageProps) *stringstatic#Return the SSM parameter name that will contain the Amazon Linux image with the given attributes.