Skip to content

Data Source: awsAmi

Use this data source to get the ID of a registered AMI for use in other resources.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.dataAwsAmi.DataAwsAmi(this, "example", {
  executableUsers: ["self"],
  filter: [
    {
      name: "name",
      values: ["myami-*"],
    },
    {
      name: "root-device-type",
      values: ["ebs"],
    },
    {
      name: "virtualization-type",
      values: ["hvm"],
    },
  ],
  mostRecent: true,
  nameRegex: "^myami-\\d{3}",
  owners: ["self"],
});

Argument Reference

  • owners - (Optional) List of AMI owners to limit search. Valid values: an AWS account ID, self (the current account), or an AWS owner alias (e.g., amazon, awsMarketplace, microsoft).

  • mostRecent - (Optional) If more than one result is returned, use the most recent AMI.

  • executableUsers - (Optional) Limit search to users with explicit launch permission on the image. Valid items are the numeric account ID or self.

  • includeDeprecated - (Optional) If true, all deprecated AMIs are included in the response. If false, no deprecated AMIs are included in the response. If no value is specified, the default value is false.

  • filter - (Optional) One or more name/value pairs to filter off of. There are several valid keys, for a full reference, check out describe-images in the AWS CLI reference.

  • nameRegex - (Optional) Regex string to apply to the AMI list returned by AWS. This allows more advanced filtering not supported from the AWS API. This filtering is done locally on what AWS returns, and could have a performance impact if the result is large. Combine this with other options to narrow down the list AWS returns.

\~> NOTE: If more or less than a single match is returned by the search, Terraform will fail. Ensure that your search is specific enough to return a single AMI ID only, or use mostRecent to choose the most recent one. If you want to match multiple AMIs, use the awsAmiIds data source instead.

Attributes Reference

id is set to the ID of the found AMI. In addition, the following attributes are exported:

\~> NOTE: Some values are not always set and may not be available for interpolation.

  • arn - ARN of the AMI.
  • architecture - OS architecture of the AMI (ie: i386 or x8664).
  • bootMode - Boot mode of the image.
  • blockDeviceMappings - Set of objects with block device mappings of the AMI.
  • deviceName - Physical name of the device.
  • ebs - Map containing EBS information, if the device is EBS based. Unlike most object attributes, these are accessed directly (e.g., ebsVolumeSize or ebs["volumeSize"]) rather than accessed through the first element of a list (e.g., ebs[0]VolumeSize).
    • deleteOnTermination - true if the EBS volume will be deleted on termination.
    • encrypted - true if the EBS volume is encrypted.
    • iops - 0 if the EBS volume is not a provisioned IOPS image, otherwise the supported IOPS count.
    • snapshotId - The ID of the snapshot.
    • volumeSize - The size of the volume, in GiB.
    • throughput - The throughput that the EBS volume supports, in MiB/s.
    • volumeType - The volume type.
  • noDevice - Suppresses the specified device included in the block device mapping of the AMI.
  • virtualName - Virtual device name (for instance stores).
  • creationDate - Date and time the image was created.
  • deprecationTime - Date and time when the image will be deprecated.
  • description - Description of the AMI that was provided during image creation.
  • hypervisor - Hypervisor type of the image.
  • imageId - ID of the AMI. Should be the same as the resource id.
  • imageLocation - Location of the AMI.
  • imageOwnerAlias - AWS account alias (for example, amazon, self) or the AWS account ID of the AMI owner.
  • imageType - Type of image.
  • imdsSupport - Instance Metadata Service (IMDS) support mode for the image. Set to v20 if instances ran from this image enforce IMDSv2.
  • kernelId - Kernel associated with the image, if any. Only applicable for machine images.
  • name - Name of the AMI that was provided during image creation.
  • ownerId - AWS account ID of the image owner.
  • platform - Value is Windows for windows AMIs; otherwise blank.
  • productCodes - Any product codes associated with the AMI.
  • productCodes.#ProductCodeId - The product code.
  • productCodes.#ProductCodeType - The type of product code.
  • public - true if the image has public launch permissions.
  • ramdiskId - RAM disk associated with the image, if any. Only applicable for machine images.
  • rootDeviceName - Device name of the root device.
  • rootDeviceType - Type of root device (ie: ebs or instanceStore).
  • rootSnapshotId - Snapshot id associated with the root device, if any (only applies to ebs root devices).
  • sriovNetSupport - Whether enhanced networking is enabled.
  • state - Current state of the AMI. If the state is available, the image is successfully registered and can be used to launch an instance.
  • stateReason - Describes a state change. Fields are unset if not available.
  • stateReasonCode - The reason code for the state change.
  • stateReasonMessage - The message for the state change.
  • tags - Any tags assigned to the image.
  • tags.#Key - Key name of the tag.
  • tags.#Value - Value of the tag.
  • tpmSupport - If the image is configured for NitroTPM support, the value is v20.
  • virtualizationType - Type of virtualization of the AMI (ie: hvm or paravirtual).
  • usageOperation - Operation of the Amazon EC2 instance and the billing code that is associated with the AMI.
  • platformDetails - Platform details associated with the billing code of the AMI.
  • enaSupport - Whether enhanced networking with ENA is enabled.

Timeouts

Configuration options:

  • read - (Default 20M)