# MachineImageType

The machine image type.

- Source: [`aws-ecs/lib/cluster.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-ecs/lib/cluster.ts#L132)

## Example

TypeScript:

```ts
declare const vpc: ec2.Vpc;
const launchTemplate = new ec2.LaunchTemplate(this, 'ASG-LaunchTemplate', {
  instanceType: new ec2.InstanceType('t3.medium'),
  machineImage: ecs.EcsOptimizedImage.amazonLinux2(),
  userData: ec2.UserData.forLinux(),
});

const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', {
  vpc,
  mixedInstancesPolicy: {
    instancesDistribution: {
      onDemandPercentageAboveBaseCapacity: 50,
    },
    launchTemplate: launchTemplate,
  },
});

const cluster = new ecs.Cluster(this, 'Cluster', { vpc });

const capacityProvider = new ecs.AsgCapacityProvider(this, 'AsgCapacityProvider', {
  autoScalingGroup,
  machineImageType: ecs.MachineImageType.AMAZON_LINUX_2,
});

cluster.addAsgCapacityProvider(capacityProvider);
```

Python:

```python
# vpc: ec2.Vpc

launch_template = ec2.LaunchTemplate(self, "ASG-LaunchTemplate",
    instance_type=ec2.InstanceType("t3.medium"),
    machine_image=ecs.EcsOptimizedImage.amazon_linux2(),
    user_data=ec2.UserData.for_linux()
)

auto_scaling_group = autoscaling.AutoScalingGroup(self, "ASG",
    vpc=vpc,
    mixed_instances_policy=autoscaling.MixedInstancesPolicy(
        instances_distribution=autoscaling.InstancesDistribution(
            on_demand_percentage_above_base_capacity=50
        ),
        launch_template=launch_template
    )
)

cluster = ecs.Cluster(self, "Cluster", vpc=vpc)

capacity_provider = ecs.AsgCapacityProvider(self, "AsgCapacityProvider",
    auto_scaling_group=auto_scaling_group,
    machine_image_type=ecs.MachineImageType.AMAZON_LINUX_2
)

cluster.add_asg_capacity_provider(capacity_provider)
```

Java:

```java
Vpc vpc;

LaunchTemplate launchTemplate = LaunchTemplate.Builder.create(this, "ASG-LaunchTemplate")
        .instanceType(new InstanceType("t3.medium"))
        .machineImage(EcsOptimizedImage.amazonLinux2())
        .userData(UserData.forLinux())
        .build();

AutoScalingGroup autoScalingGroup = AutoScalingGroup.Builder.create(this, "ASG")
        .vpc(vpc)
        .mixedInstancesPolicy(MixedInstancesPolicy.builder()
                .instancesDistribution(InstancesDistribution.builder()
                        .onDemandPercentageAboveBaseCapacity(50)
                        .build())
                .launchTemplate(launchTemplate)
                .build())
        .build();

Cluster cluster = Cluster.Builder.create(this, "Cluster").vpc(vpc).build();

AsgCapacityProvider capacityProvider = AsgCapacityProvider.Builder.create(this, "AsgCapacityProvider")
        .autoScalingGroup(autoScalingGroup)
        .machineImageType(MachineImageType.AMAZON_LINUX_2)
        .build();

cluster.addAsgCapacityProvider(capacityProvider);
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Vpc vpc;

var launchTemplate = new LaunchTemplate(this, "ASG-LaunchTemplate", new LaunchTemplateProps {
    InstanceType = new InstanceType("t3.medium"),
    MachineImage = EcsOptimizedImage.AmazonLinux2(),
    UserData = UserData.ForLinux()
});

var autoScalingGroup = new AutoScalingGroup(this, "ASG", new AutoScalingGroupProps {
    Vpc = vpc,
    MixedInstancesPolicy = new MixedInstancesPolicy {
        InstancesDistribution = new InstancesDistribution {
            OnDemandPercentageAboveBaseCapacity = 50
        },
        LaunchTemplate = launchTemplate
    }
});

var cluster = new Cluster(this, "Cluster", new ClusterProps { Vpc = vpc });

var capacityProvider = new AsgCapacityProvider(this, "AsgCapacityProvider", new AsgCapacityProviderProps {
    AutoScalingGroup = autoScalingGroup,
    MachineImageType = MachineImageType.AMAZON_LINUX_2
});

cluster.AddAsgCapacityProvider(capacityProvider);
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc Vpc

launchTemplate := ec2.NewLaunchTemplate(this, jsii.String("ASG-LaunchTemplate"), &LaunchTemplateProps{
	InstanceType: ec2.NewInstanceType(jsii.String("t3.medium")),
	MachineImage: ecs.EcsOptimizedImage_AmazonLinux2(),
	UserData: ec2.UserData_ForLinux(),
})

autoScalingGroup := autoscaling.NewAutoScalingGroup(this, jsii.String("ASG"), &AutoScalingGroupProps{
	Vpc: Vpc,
	MixedInstancesPolicy: &MixedInstancesPolicy{
		InstancesDistribution: &InstancesDistribution{
			OnDemandPercentageAboveBaseCapacity: jsii.Number(50),
		},
		LaunchTemplate: launchTemplate,
	},
})

cluster := ecs.NewCluster(this, jsii.String("Cluster"), &ClusterProps{
	Vpc: Vpc,
})

capacityProvider := ecs.NewAsgCapacityProvider(this, jsii.String("AsgCapacityProvider"), &AsgCapacityProviderProps{
	AutoScalingGroup: AutoScalingGroup,
	MachineImageType: ecs.MachineImageType_AMAZON_LINUX_2,
})

cluster.AddAsgCapacityProvider(capacityProvider)
```

## Members

| Member | Description |
| --- | --- |
| `AMAZON_LINUX_2` | Amazon ECS-optimized Amazon Linux 2 AMI. |
| `BOTTLEROCKET` | Bottlerocket AMI. |

## Referenced by

- [`AddAutoScalingGroupCapacityOptions`](/v2/docs/aws-cdk-lib.aws_ecs.AddAutoScalingGroupCapacityOptions).machineImageType
- [`AsgCapacityProvider`](/v2/docs/aws-cdk-lib.aws_ecs.AsgCapacityProvider).machineImageType
