MachineImage Class
Factory functions for standard Amazon Machine Image objects.
Example
declare const vpc: ec2.Vpc;
const mySecurityGroup = new ec2.SecurityGroup(this, 'SecurityGroup', { vpc });
new autoscaling.AutoScalingGroup(this, 'ASG', {
vpc,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
machineImage: ec2.MachineImage.latestAmazonLinux2(),
securityGroup: mySecurityGroup,
});
Initializer
new MachineImage()
MachineImage()
new MachineImage()
new MachineImage()
NewMachineImage()
Methods
fromSsmParameter(parameterName: string, options?: SsmParameterImageOptions): IMachineImage@staticmethod def from_ssm_parameter(parameter_name: str, options: typing.Optional[SsmParameterImageOptions] = None) -> IMachineImagepublic static IMachineImage fromSsmParameter(String parameterName, SsmParameterImageOptions options)public static IMachineImage FromSsmParameter(string parameterName, SsmParameterImageOptions? options = null)func FromSsmParameter(ParameterName *string, Options SsmParameterImageOptions) IMachineImagestatic#notes
By default, the SSM parameter is refreshed at every deployment, causing your instances to be replaced whenever a new version of the AMI is released.
Pass { cachedInContext: true } to keep the AMI ID stable. If you do, you will have to remember to periodically invalidate the context to refresh to the newest AMI ID.
genericLinux(amiMap: { [key: string]: string }, props?: GenericLinuxImageProps): IMachineImage@staticmethod def generic_linux(ami_map: typing.Mapping[str, str], props: typing.Optional[GenericLinuxImageProps] = None) -> IMachineImagepublic static IMachineImage genericLinux(Map<String, String> amiMap, GenericLinuxImageProps props)public static IMachineImage GenericLinux(IDictionary<string, string> amiMap, GenericLinuxImageProps? props = null)func GenericLinux(AmiMap *map[string]*string, Props GenericLinuxImageProps) IMachineImagestatic#2 parameters
Parameters
amiMapami_mapamiMapamiMapAmiMap— For every region where you are deploying the stack, specify the AMI ID for that region.propspropspropspropsProps— Customize the image by supplying additional props.
genericWindows(amiMap: { [key: string]: string }, props?: GenericWindowsImageProps): IMachineImage@staticmethod def generic_windows(ami_map: typing.Mapping[str, str], props: typing.Optional[GenericWindowsImageProps] = None) -> IMachineImagepublic static IMachineImage genericWindows(Map<String, String> amiMap, GenericWindowsImageProps props)public static IMachineImage GenericWindows(IDictionary<string, string> amiMap, GenericWindowsImageProps? props = null)func GenericWindows(AmiMap *map[string]*string, Props GenericWindowsImageProps) IMachineImagestatic#2 parameters
Parameters
amiMapami_mapamiMapamiMapAmiMap— For every region where you are deploying the stack, specify the AMI ID for that region.propspropspropspropsProps— Customize the image by supplying additional props.
latestAmazonLinux(props?: AmazonLinuxImageProps): IMachineImage@staticmethod def latest_amazon_linux(props: typing.Optional[AmazonLinuxImageProps] = None) -> IMachineImagepublic static IMachineImage latestAmazonLinux(AmazonLinuxImageProps props)public static IMachineImage LatestAmazonLinux(AmazonLinuxImageProps? props = null)func LatestAmazonLinux(Props AmazonLinuxImageProps) IMachineImagestaticdeprecated#notes
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.
N.B.: "latest" in the name of this function indicates that it always uses the most recent image of a particular generation of Amazon Linux, not that it uses the "latest generation". For backwards compatibility, this function uses Amazon Linux 1 if no generation is specified.
Specify the desired generation using the generation property:
ec2.MachineImage.latestAmazonLinux({
// Use Amazon Linux 2
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2,
})
latestAmazonLinux2(props?: AmazonLinux2ImageSsmParameterProps): IMachineImage@staticmethod def latest_amazon_linux2(props: typing.Optional[AmazonLinux2ImageSsmParameterProps] = None) -> IMachineImagepublic static IMachineImage latestAmazonLinux2(AmazonLinux2ImageSsmParameterProps props)public static IMachineImage LatestAmazonLinux2(AmazonLinux2ImageSsmParameterProps? props = null)func LatestAmazonLinux2(Props AmazonLinux2ImageSsmParameterProps) IMachineImagestatic#notes
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.
latestAmazonLinux2022(props?: AmazonLinux2022ImageSsmParameterProps): IMachineImage@staticmethod def latest_amazon_linux2022(props: typing.Optional[AmazonLinux2022ImageSsmParameterProps] = None) -> IMachineImagepublic static IMachineImage latestAmazonLinux2022(AmazonLinux2022ImageSsmParameterProps props)public static IMachineImage LatestAmazonLinux2022(AmazonLinux2022ImageSsmParameterProps? props = null)func LatestAmazonLinux2022(Props AmazonLinux2022ImageSsmParameterProps) IMachineImagestaticdeprecated#notes
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.
latestAmazonLinux2023(props?: AmazonLinux2023ImageSsmParameterProps): IMachineImage@staticmethod def latest_amazon_linux2023(props: typing.Optional[AmazonLinux2023ImageSsmParameterProps] = None) -> IMachineImagepublic static IMachineImage latestAmazonLinux2023(AmazonLinux2023ImageSsmParameterProps props)public static IMachineImage LatestAmazonLinux2023(AmazonLinux2023ImageSsmParameterProps? props = null)func LatestAmazonLinux2023(Props AmazonLinux2023ImageSsmParameterProps) IMachineImagestatic#notes
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.
latestWindows(version: WindowsVersion, props?: WindowsImageProps): IMachineImage@staticmethod def latest_windows(version: WindowsVersion, props: typing.Optional[WindowsImageProps] = None) -> IMachineImagepublic static IMachineImage latestWindows(WindowsVersion version, WindowsImageProps props)public static IMachineImage LatestWindows(WindowsVersion version, WindowsImageProps? props = null)func LatestWindows(Version WindowsVersion, Props WindowsImageProps) IMachineImagestatic#notes
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.
lookup(props: LookupMachineImageProps): IMachineImage@staticmethod def lookup(props: LookupMachineImageProps) -> IMachineImagepublic static IMachineImage lookup(LookupMachineImageProps props)public static IMachineImage Lookup(LookupMachineImageProps props)func Lookup(Props LookupMachineImageProps) IMachineImagestatic#notes
The most recent, available, launchable image matching the given filter criteria will be used. Looking up AMIs may take a long time; specify as many filter criteria as possible to narrow down the search.
The AMI selected will be cached in cdk.context.json and the same value will be used on future runs. To refresh the AMI lookup, you will have to evict the value from the cache using the cdk context command. See https://docs.aws.amazon.com/cdk/latest/guide/context.html for more information.
This function can not be used in environment-agnostic stacks.
resolveSsmParameterAtLaunch(parameterName: string, options?: SsmParameterImageOptions): IMachineImage@staticmethod def resolve_ssm_parameter_at_launch(parameter_name: str, options: typing.Optional[SsmParameterImageOptions] = None) -> IMachineImagepublic static IMachineImage resolveSsmParameterAtLaunch(String parameterName, SsmParameterImageOptions options)public static IMachineImage ResolveSsmParameterAtLaunch(string parameterName, SsmParameterImageOptions? options = null)func ResolveSsmParameterAtLaunch(ParameterName *string, Options SsmParameterImageOptions) IMachineImagestatic#The AMI ID will be resolved at instance launch time.
2 parameters
Parameters
parameterNameparameter_nameparameterNameparameterNameParameterName— The name of SSM parameter containing the AMI ID.optionsoptionsoptionsoptionsOptions— The parameter image options.