aws-cdk-lib.aws_ecs.EcsOptimizedImage

class EcsOptimizedImage

LanguageType name
.NETAmazon.CDK.AWS.ECS.EcsOptimizedImage
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsecs#EcsOptimizedImage
Javasoftware.amazon.awscdk.services.ecs.EcsOptimizedImage
Pythonaws_cdk.aws_ecs.EcsOptimizedImage
TypeScript (source)aws-cdk-lib » aws_ecs » EcsOptimizedImage

Implements IMachineImage

Construct a Linux or Windows machine image from the latest ECS Optimized AMI published in SSM.

Example

declare const vpc: ec2.Vpc;

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

// Either add default capacity
cluster.addCapacity('DefaultAutoScalingGroupCapacity', {
  instanceType: new ec2.InstanceType("t2.xlarge"),
  desiredCapacity: 3,
});

// Or add customized capacity. Be sure to start the Amazon ECS-optimized AMI.
const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', {
  vpc,
  instanceType: new ec2.InstanceType('t2.xlarge'),
  machineImage: ecs.EcsOptimizedImage.amazonLinux(),
  // Or use Amazon ECS-Optimized Amazon Linux 2 AMI
  // machineImage: EcsOptimizedImage.amazonLinux2(),
  desiredCapacity: 3,
  // ... other options here ...
});

const capacityProvider = new ecs.AsgCapacityProvider(this, 'AsgCapacityProvider', {
  autoScalingGroup,
});
cluster.addAsgCapacityProvider(capacityProvider);

Methods

NameDescription
getImage(scope)Return the correct image.
static amazonLinux(options?)Construct an Amazon Linux AMI image from the latest ECS Optimized AMI published in SSM.
static amazonLinux2(hardwareType?, options?)Construct an Amazon Linux 2 image from the latest ECS Optimized AMI published in SSM.
static windows(windowsVersion, options?)Construct a Windows image from the latest ECS Optimized AMI published in SSM.

getImage(scope)

public getImage(scope: Construct): MachineImageConfig

Parameters

  • scope Construct

Returns

  • MachineImageConfig

Return the correct image.


static amazonLinux(options?)

public static amazonLinux(options?: EcsOptimizedImageOptions): EcsOptimizedImage

Parameters

  • options EcsOptimizedImageOptions

Returns

  • EcsOptimizedImage

Construct an Amazon Linux AMI image from the latest ECS Optimized AMI published in SSM.


static amazonLinux2(hardwareType?, options?)

public static amazonLinux2(hardwareType?: AmiHardwareType, options?: EcsOptimizedImageOptions): EcsOptimizedImage

Parameters

  • hardwareType AmiHardwareType — ECS-optimized AMI variant to use.
  • options EcsOptimizedImageOptions

Returns

  • EcsOptimizedImage

Construct an Amazon Linux 2 image from the latest ECS Optimized AMI published in SSM.


static windows(windowsVersion, options?)

public static windows(windowsVersion: WindowsOptimizedVersion, options?: EcsOptimizedImageOptions): EcsOptimizedImage

Parameters

  • windowsVersion WindowsOptimizedVersion — Windows Version to use.
  • options EcsOptimizedImageOptions

Returns

  • EcsOptimizedImage

Construct a Windows image from the latest ECS Optimized AMI published in SSM.