aws-cdk-lib.aws_ec2.AmazonLinuxImage

class AmazonLinuxImage

LanguageType name
.NETAmazon.CDK.AWS.EC2.AmazonLinuxImage
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsec2#AmazonLinuxImage
Javasoftware.amazon.awscdk.services.ec2.AmazonLinuxImage
Pythonaws_cdk.aws_ec2.AmazonLinuxImage
TypeScript (source)aws-cdk-lib » aws_ec2 » AmazonLinuxImage

Implements IMachineImage

Extends GenericSSMParameterImage

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

const sg = ec2.SecurityGroup.fromSecurityGroupId(this, 'FsxSecurityGroup', '{SECURITY-GROUP-ID}');
const fs = fsx.LustreFileSystem.fromLustreFileSystemAttributes(this, 'FsxLustreFileSystem', {
  dnsName: '{FILE-SYSTEM-DNS-NAME}',
  fileSystemId: '{FILE-SYSTEM-ID}',
  securityGroup: sg,
});

const vpc = ec2.Vpc.fromVpcAttributes(this, 'Vpc', {
  availabilityZones: ['us-west-2a', 'us-west-2b'],
  publicSubnetIds: ['{US-WEST-2A-SUBNET-ID}', '{US-WEST-2B-SUBNET-ID}'],
  vpcId: '{VPC-ID}',
});

const inst = new ec2.Instance(this, 'inst', {
  instanceType: ec2.InstanceType.of(ec2.InstanceClass.T2, ec2.InstanceSize.LARGE),
  machineImage: new ec2.AmazonLinuxImage({
    generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2,
  }),
  vpc,
  vpcSubnets: {
    subnetType: ec2.SubnetType.PUBLIC,
  },
});

fs.connections.allowDefaultPortFrom(inst);

Initializer

new AmazonLinuxImage(props?: AmazonLinuxImageProps)

Parameters

  • props AmazonLinuxImageProps

Properties

NameTypeDescription
parameterNamestringName of the SSM parameter we're looking up.

parameterName

Type: string

Name of the SSM parameter we're looking up.

Methods

NameDescription
getImage(scope)Return the image to use in the given context.
static ssmParameterName(props?)Return the SSM parameter name that will contain the Amazon Linux image with the given attributes.

getImage(scope)

public getImage(scope: Construct): MachineImageConfig

Parameters

  • scope Construct

Returns

  • MachineImageConfig

Return the image to use in the given context.


static ssmParameterName(props?)

public static ssmParameterName(props?: AmazonLinuxImageProps): string

Parameters

  • props AmazonLinuxImageProps

Returns

  • string

Return the SSM parameter name that will contain the Amazon Linux image with the given attributes.