Class MachineImage
Factory functions for standard Amazon Machine Image objects.
Inheritance
Namespace: Amazon.CDK.AWS.EC2
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public abstract class MachineImage : DeputyBase
Syntax (vb)
Public MustInherit Class MachineImage
Inherits DeputyBase
Remarks
ExampleMetadata: infused
Examples
Vpc vpc;
var mySecurityGroup = new SecurityGroup(this, "SecurityGroup", new SecurityGroupProps { Vpc = vpc });
new AutoScalingGroup(this, "ASG", new AutoScalingGroupProps {
Vpc = vpc,
InstanceType = InstanceType.Of(InstanceClass.BURSTABLE2, InstanceSize.MICRO),
MachineImage = MachineImage.LatestAmazonLinux2(),
SecurityGroup = mySecurityGroup
});
Synopsis
Constructors
MachineImage() | |
MachineImage(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
MachineImage(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
Methods
FromSsmParameter(String, ISsmParameterImageOptions) | An image specified in SSM parameter store. |
GenericLinux(IDictionary<String, String>, IGenericLinuxImageProps) | A Linux image where you specify the AMI ID for every region. |
GenericWindows(IDictionary<String, String>, IGenericWindowsImageProps) | A Windows image where you specify the AMI ID for every region. |
LatestAmazonLinux(IAmazonLinuxImageProps) | (deprecated) An Amazon Linux image that is automatically kept up-to-date. |
LatestAmazonLinux2(IAmazonLinux2ImageSsmParameterProps) | An Amazon Linux 2 image that is automatically kept up-to-date. |
LatestAmazonLinux2022(IAmazonLinux2022ImageSsmParameterProps) | (deprecated) An Amazon Linux 2022 image that is automatically kept up-to-date. |
LatestAmazonLinux2023(IAmazonLinux2023ImageSsmParameterProps) | An Amazon Linux 2023 image that is automatically kept up-to-date. |
LatestWindows(WindowsVersion, IWindowsImageProps) | A Windows image that is automatically kept up-to-date. |
Lookup(ILookupMachineImageProps) | Look up a shared Machine Image using DescribeImages. |
ResolveSsmParameterAtLaunch(String, ISsmParameterImageOptions) | An image specified in SSM parameter store that will be resolved at instance launch time. |
Constructors
MachineImage()
protected MachineImage()
MachineImage(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected MachineImage(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
MachineImage(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected MachineImage(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Methods
FromSsmParameter(String, ISsmParameterImageOptions)
An image specified in SSM parameter store.
public static IMachineImage FromSsmParameter(string parameterName, ISsmParameterImageOptions options = null)
Parameters
- parameterName System.String
- options ISsmParameterImageOptions
Returns
Remarks
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(IDictionary<String, String>, IGenericLinuxImageProps)
A Linux image where you specify the AMI ID for every region.
public static IMachineImage GenericLinux(IDictionary<string, string> amiMap, IGenericLinuxImageProps props = null)
Parameters
- amiMap System.Collections.Generic.IDictionary<System.String, System.String>
For every region where you are deploying the stack, specify the AMI ID for that region.
- props IGenericLinuxImageProps
Customize the image by supplying additional props.
Returns
GenericWindows(IDictionary<String, String>, IGenericWindowsImageProps)
A Windows image where you specify the AMI ID for every region.
public static IMachineImage GenericWindows(IDictionary<string, string> amiMap, IGenericWindowsImageProps props = null)
Parameters
- amiMap System.Collections.Generic.IDictionary<System.String, System.String>
For every region where you are deploying the stack, specify the AMI ID for that region.
- props IGenericWindowsImageProps
Customize the image by supplying additional props.
Returns
LatestAmazonLinux(IAmazonLinuxImageProps)
(deprecated) An Amazon Linux image that is automatically kept up-to-date.
public static IMachineImage LatestAmazonLinux(IAmazonLinuxImageProps props = null)
Parameters
- props IAmazonLinuxImageProps
Returns
Remarks
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:
MachineImage.LatestAmazonLinux(new AmazonLinuxImageProps {
// Use Amazon Linux 2
Generation = AmazonLinuxGeneration.AMAZON_LINUX_2
});
Stability: Deprecated
LatestAmazonLinux2(IAmazonLinux2ImageSsmParameterProps)
An Amazon Linux 2 image that is automatically kept up-to-date.
public static IMachineImage LatestAmazonLinux2(IAmazonLinux2ImageSsmParameterProps props = null)
Parameters
Returns
Remarks
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(IAmazonLinux2022ImageSsmParameterProps)
(deprecated) An Amazon Linux 2022 image that is automatically kept up-to-date.
public static IMachineImage LatestAmazonLinux2022(IAmazonLinux2022ImageSsmParameterProps props = null)
Parameters
Returns
Remarks
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.
Stability: Deprecated
LatestAmazonLinux2023(IAmazonLinux2023ImageSsmParameterProps)
An Amazon Linux 2023 image that is automatically kept up-to-date.
public static IMachineImage LatestAmazonLinux2023(IAmazonLinux2023ImageSsmParameterProps props = null)
Parameters
Returns
Remarks
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(WindowsVersion, IWindowsImageProps)
A Windows image that is automatically kept up-to-date.
public static IMachineImage LatestWindows(WindowsVersion version, IWindowsImageProps props = null)
Parameters
- version WindowsVersion
- props IWindowsImageProps
Returns
Remarks
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(ILookupMachineImageProps)
Look up a shared Machine Image using DescribeImages.
public static IMachineImage Lookup(ILookupMachineImageProps props)
Parameters
- props ILookupMachineImageProps
Returns
Remarks
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(String, ISsmParameterImageOptions)
An image specified in SSM parameter store that will be resolved at instance launch time.
public static IMachineImage ResolveSsmParameterAtLaunch(string parameterName, ISsmParameterImageOptions options = null)
Parameters
- parameterName System.String
The name of SSM parameter containing the AMI ID.
- options ISsmParameterImageOptions
The parameter image options.
Returns
Remarks
The AMI ID will be resolved at instance launch time.
See: https://docs.aws.amazon.com/autoscaling/ec2/userguide/using-systems-manager-parameters.html