Class: AWSCDK::EC2::MachineImage

Inherits:
Jsii::Object
  • Object
show all
Defined in:
ec2/machine_image.rb

Overview

Factory functions for standard Amazon Machine Image objects.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMachineImage

Returns a new instance of MachineImage.



8
9
10
# File 'ec2/machine_image.rb', line 8

def initialize
  Jsii::Object.instance_method(:initialize).bind(self).call
end

Class Method Details

.from_ssm_parameter(parameter_name, options = nil) ⇒ AWSCDK::EC2::IMachineImage

An image specified in SSM parameter store.

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.

Parameters:

Returns:



30
31
32
33
34
35
# File 'ec2/machine_image.rb', line 30

def self.from_ssm_parameter(parameter_name, options = nil)
  Jsii::Type.check_type(parameter_name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "parameterName")
  options = options.is_a?(Hash) ? ::AWSCDK::EC2::SSMParameterImageOptions.new(**options.transform_keys(&:to_sym)) : options
  Jsii::Type.check_type(options, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLlNzbVBhcmFtZXRlckltYWdlT3B0aW9ucyJ9")), "options") unless options.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_ec2.MachineImage", "fromSsmParameter", [parameter_name, options])
end

.generic_linux(ami_map, props = nil) ⇒ AWSCDK::EC2::IMachineImage

A Linux image where you specify the AMI ID for every region.

Parameters:

  • ami_map (Hash{String => String})

    For every region where you are deploying the stack, specify the AMI ID for that region.

  • props (AWSCDK::EC2::GenericLinuxImageProps, nil) (defaults to: nil)

    Customize the image by supplying additional props.

Returns:



42
43
44
45
46
47
# File 'ec2/machine_image.rb', line 42

def self.generic_linux(ami_map, props = nil)
  Jsii::Type.check_type(ami_map, JSON.parse(Base64.strict_decode64("eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7InByaW1pdGl2ZSI6InN0cmluZyJ9LCJraW5kIjoibWFwIn19")), "amiMap")
  props = props.is_a?(Hash) ? ::AWSCDK::EC2::GenericLinuxImageProps.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLkdlbmVyaWNMaW51eEltYWdlUHJvcHMifQ==")), "props") unless props.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_ec2.MachineImage", "genericLinux", [ami_map, props])
end

.generic_windows(ami_map, props = nil) ⇒ AWSCDK::EC2::IMachineImage

A Windows image where you specify the AMI ID for every region.

Parameters:

  • ami_map (Hash{String => String})

    For every region where you are deploying the stack, specify the AMI ID for that region.

  • props (AWSCDK::EC2::GenericWindowsImageProps, nil) (defaults to: nil)

    Customize the image by supplying additional props.

Returns:



54
55
56
57
58
59
# File 'ec2/machine_image.rb', line 54

def self.generic_windows(ami_map, props = nil)
  Jsii::Type.check_type(ami_map, JSON.parse(Base64.strict_decode64("eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7InByaW1pdGl2ZSI6InN0cmluZyJ9LCJraW5kIjoibWFwIn19")), "amiMap")
  props = props.is_a?(Hash) ? ::AWSCDK::EC2::GenericWindowsImageProps.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLkdlbmVyaWNXaW5kb3dzSW1hZ2VQcm9wcyJ9")), "props") unless props.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_ec2.MachineImage", "genericWindows", [ami_map, props])
end

.jsii_overridable_methodsObject



12
13
14
15
# File 'ec2/machine_image.rb', line 12

def self.jsii_overridable_methods
  {
  }
end

.latest_amazon_linux(props = nil) ⇒ AWSCDK::EC2::IMachineImage

Deprecated.

use MachineImage.latestAmazonLinux2 instead

An Amazon Linux image that is automatically kept up-to-date.

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:

AWSCDK::EC2::MachineImage.latest_amazon_linux({
    # Use Amazon Linux 2
    generation: AWSCDK::EC2::AmazonLinuxGeneration::AMAZON_LINUX_2,
})

Parameters:

Returns:



85
86
87
88
89
# File 'ec2/machine_image.rb', line 85

def self.latest_amazon_linux(props = nil)
  props = props.is_a?(Hash) ? ::AWSCDK::EC2::AmazonLinuxImageProps.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLkFtYXpvbkxpbnV4SW1hZ2VQcm9wcyJ9")), "props") unless props.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_ec2.MachineImage", "latestAmazonLinux", [props])
end

.latest_amazon_linux2(props = nil) ⇒ AWSCDK::EC2::IMachineImage

An Amazon Linux 2 image that is automatically kept up-to-date.

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.

Parameters:

Returns:



100
101
102
103
104
# File 'ec2/machine_image.rb', line 100

def self.latest_amazon_linux2(props = nil)
  props = props.is_a?(Hash) ? ::AWSCDK::EC2::AmazonLinux2ImageSSMParameterProps.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLkFtYXpvbkxpbnV4MkltYWdlU3NtUGFyYW1ldGVyUHJvcHMifQ==")), "props") unless props.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_ec2.MachineImage", "latestAmazonLinux2", [props])
end

.latest_amazon_linux2022(props = nil) ⇒ AWSCDK::EC2::IMachineImage

Deprecated.
  • use latestAmazonLinux2023() instead

An Amazon Linux 2022 image that is automatically kept up-to-date.

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.

Parameters:

Returns:



116
117
118
119
120
# File 'ec2/machine_image.rb', line 116

def self.latest_amazon_linux2022(props = nil)
  props = props.is_a?(Hash) ? ::AWSCDK::EC2::AmazonLinux2022ImageSSMParameterProps.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLkFtYXpvbkxpbnV4MjAyMkltYWdlU3NtUGFyYW1ldGVyUHJvcHMifQ==")), "props") unless props.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_ec2.MachineImage", "latestAmazonLinux2022", [props])
end

.latest_amazon_linux2023(props = nil) ⇒ AWSCDK::EC2::IMachineImage

An Amazon Linux 2023 image that is automatically kept up-to-date.

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.

Parameters:

Returns:



131
132
133
134
135
# File 'ec2/machine_image.rb', line 131

def self.latest_amazon_linux2023(props = nil)
  props = props.is_a?(Hash) ? ::AWSCDK::EC2::AmazonLinux2023ImageSSMParameterProps.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLkFtYXpvbkxpbnV4MjAyM0ltYWdlU3NtUGFyYW1ldGVyUHJvcHMifQ==")), "props") unless props.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_ec2.MachineImage", "latestAmazonLinux2023", [props])
end

.latest_windows(version, props = nil) ⇒ AWSCDK::EC2::IMachineImage

A Windows image that is automatically kept up-to-date.

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.

Parameters:

Returns:



147
148
149
150
151
152
# File 'ec2/machine_image.rb', line 147

def self.latest_windows(version, props = nil)
  Jsii::Type.check_type(version, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLldpbmRvd3NWZXJzaW9uIn0=")), "version")
  props = props.is_a?(Hash) ? ::AWSCDK::EC2::WindowsImageProps.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLldpbmRvd3NJbWFnZVByb3BzIn0=")), "props") unless props.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_ec2.MachineImage", "latestWindows", [version, props])
end

.lookup(props) ⇒ AWSCDK::EC2::IMachineImage

Look up a shared Machine Image using DescribeImages.

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.



169
170
171
172
173
# File 'ec2/machine_image.rb', line 169

def self.lookup(props)
  props = props.is_a?(Hash) ? ::AWSCDK::EC2::LookupMachineImageProps.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLkxvb2t1cE1hY2hpbmVJbWFnZVByb3BzIn0=")), "props")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_ec2.MachineImage", "lookup", [props])
end

.resolve_ssm_parameter_at_launch(parameter_name, options = nil) ⇒ AWSCDK::EC2::IMachineImage

An image specified in SSM parameter store that will be resolved at instance launch time.

The AMI ID will be resolved at instance launch time.

Parameters:

Returns:

See Also:



183
184
185
186
187
188
# File 'ec2/machine_image.rb', line 183

def self.resolve_ssm_parameter_at_launch(parameter_name, options = nil)
  Jsii::Type.check_type(parameter_name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "parameterName")
  options = options.is_a?(Hash) ? ::AWSCDK::EC2::SSMParameterImageOptions.new(**options.transform_keys(&:to_sym)) : options
  Jsii::Type.check_type(options, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWMyLlNzbVBhcmFtZXRlckltYWdlT3B0aW9ucyJ9")), "options") unless options.nil?
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_ec2.MachineImage", "resolveSsmParameterAtLaunch", [parameter_name, options])
end