# AmazonLinuxImage

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.

Extends: [GenericSSMParameterImage](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.GenericSSMParameterImage.html) › AmazonLinuxImage
Implements: [IMachineImage](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IMachineImage.html)

- Source: [`aws-ec2/lib/machine-image/machine-image.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts#L493)

## Example

TypeScript:

```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:

```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:

```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));
```

C# / .NET:

```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));
```

Golang:

```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

TypeScript:

```ts
new AmazonLinuxImage(props?: AmazonLinuxImageProps)
```

Python:

```python
AmazonLinuxImage(props: typing.Optional[AmazonLinuxImageProps] = None)
```

Java:

```java
new AmazonLinuxImage(AmazonLinuxImageProps props)
```

C# / .NET:

```csharp
new AmazonLinuxImage(AmazonLinuxImageProps? props = null)
```

Golang:

```go
NewAmazonLinuxImage(Props AmazonLinuxImageProps)
```

## Properties

- `parameterName`: string — Name of the SSM parameter we're looking up.

## Methods

- `getImage(scope: Construct): MachineImageConfig` — Return the image to use in the given context.

- `ssmParameterName(props?: AmazonLinuxImageProps): string` (static) — Return the SSM parameter name that will contain the Amazon Linux image with the given attributes.
