Welcome to Pulumi Registry, your window into the cloud. Read the announcement.

AWS Classic

v4.30.0 published on Tuesday, Nov 30, 2021 by Pulumi

getAmi

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

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var example = Output.Create(Aws.Ec2.GetAmi.InvokeAsync(new Aws.Ec2.GetAmiArgs
        {
            ExecutableUsers = 
            {
                "self",
            },
            Filters = 
            {
                new Aws.Ec2.Inputs.GetAmiFilterArgs
                {
                    Name = "name",
                    Values = 
                    {
                        "myami-*",
                    },
                },
                new Aws.Ec2.Inputs.GetAmiFilterArgs
                {
                    Name = "root-device-type",
                    Values = 
                    {
                        "ebs",
                    },
                },
                new Aws.Ec2.Inputs.GetAmiFilterArgs
                {
                    Name = "virtualization-type",
                    Values = 
                    {
                        "hvm",
                    },
                },
            },
            MostRecent = true,
            NameRegex = "^myami-\\d{3}",
            Owners = 
            {
                "self",
            },
        }));
    }

}
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		opt0 := true
		opt1 := "^myami-\\d{3}"
		_, err := ec2.LookupAmi(ctx, &ec2.LookupAmiArgs{
			ExecutableUsers: []string{
				"self",
			},
			Filters: []ec2.GetAmiFilter{
				ec2.GetAmiFilter{
					Name: "name",
					Values: []string{
						"myami-*",
					},
				},
				ec2.GetAmiFilter{
					Name: "root-device-type",
					Values: []string{
						"ebs",
					},
				},
				ec2.GetAmiFilter{
					Name: "virtualization-type",
					Values: []string{
						"hvm",
					},
				},
			},
			MostRecent: &opt0,
			NameRegex:  &opt1,
			Owners: []string{
				"self",
			},
		}, nil)
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_aws as aws

example = aws.ec2.get_ami(executable_users=["self"],
    filters=[
        aws.ec2.GetAmiFilterArgs(
            name="name",
            values=["myami-*"],
        ),
        aws.ec2.GetAmiFilterArgs(
            name="root-device-type",
            values=["ebs"],
        ),
        aws.ec2.GetAmiFilterArgs(
            name="virtualization-type",
            values=["hvm"],
        ),
    ],
    most_recent=True,
    name_regex="^myami-\\d{3}",
    owners=["self"])
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = pulumi.output(aws.ec2.getAmi({
    executableUsers: ["self"],
    filters: [
        {
            name: "name",
            values: ["myami-*"],
        },
        {
            name: "root-device-type",
            values: ["ebs"],
        },
        {
            name: "virtualization-type",
            values: ["hvm"],
        },
    ],
    mostRecent: true,
    nameRegex: "^myami-\\d{3}",
    owners: ["self"],
}));

Using getAmi

Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

function getAmi(args: GetAmiArgs, opts?: InvokeOptions): Promise<GetAmiResult>
function getAmiOutput(args: GetAmiOutputArgs, opts?: InvokeOptions): Output<GetAmiResult>
def get_ami(executable_users: Optional[Sequence[str]] = None,
            filters: Optional[Sequence[GetAmiFilter]] = None,
            most_recent: Optional[bool] = None,
            name_regex: Optional[str] = None,
            owners: Optional[Sequence[str]] = None,
            tags: Optional[Mapping[str, str]] = None,
            opts: Optional[InvokeOptions] = None) -> GetAmiResult
def get_ami_output(executable_users: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
            filters: Optional[pulumi.Input[Sequence[pulumi.Input[GetAmiFilterArgs]]]] = None,
            most_recent: Optional[pulumi.Input[bool]] = None,
            name_regex: Optional[pulumi.Input[str]] = None,
            owners: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
            tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
            opts: Optional[InvokeOptions] = None) -> Output[GetAmiResult]
func LookupAmi(ctx *Context, args *LookupAmiArgs, opts ...InvokeOption) (*LookupAmiResult, error)
func LookupAmiOutput(ctx *Context, args *LookupAmiOutputArgs, opts ...InvokeOption) LookupAmiResultOutput

> Note: This function is named LookupAmi in the Go SDK.

public static class GetAmi 
{
    public static Task<GetAmiResult> InvokeAsync(GetAmiArgs args, InvokeOptions? opts = null)
    public static Output<GetAmiResult> Invoke(GetAmiInvokeArgs args, InvokeOptions? opts = null)
}

The following arguments are supported:

Owners List<string>
List of AMI owners to limit search. At least 1 value must be specified. Valid values: an AWS account ID, self (the current account), or an AWS owner alias (e.g., amazon, aws-marketplace, microsoft).
ExecutableUsers List<string>
Limit search to users with explicit launch permission on the image. Valid items are the numeric account ID or self.
Filters List<Pulumi.Aws.Ec2.Inputs.GetAmiFilter>
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][1].
MostRecent bool
If more than one result is returned, use the most recent AMI.
NameRegex string
A 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. It is recommended to combine this with other options to narrow down the list AWS returns.
Tags Dictionary<string, string>

Any tags assigned to the image.

  • tags.#.key - The key name of the tag.
  • tags.#.value - The value of the tag.
Owners []string
List of AMI owners to limit search. At least 1 value must be specified. Valid values: an AWS account ID, self (the current account), or an AWS owner alias (e.g., amazon, aws-marketplace, microsoft).
ExecutableUsers []string
Limit search to users with explicit launch permission on the image. Valid items are the numeric account ID or self.
Filters []GetAmiFilter
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][1].
MostRecent bool
If more than one result is returned, use the most recent AMI.
NameRegex string
A 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. It is recommended to combine this with other options to narrow down the list AWS returns.
Tags map[string]string

Any tags assigned to the image.

  • tags.#.key - The key name of the tag.
  • tags.#.value - The value of the tag.
owners string[]
List of AMI owners to limit search. At least 1 value must be specified. Valid values: an AWS account ID, self (the current account), or an AWS owner alias (e.g., amazon, aws-marketplace, microsoft).
executableUsers string[]
Limit search to users with explicit launch permission on the image. Valid items are the numeric account ID or self.
filters GetAmiFilter[]
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][1].
mostRecent boolean
If more than one result is returned, use the most recent AMI.
nameRegex string
A 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. It is recommended to combine this with other options to narrow down the list AWS returns.
tags {[key: string]: string}

Any tags assigned to the image.

  • tags.#.key - The key name of the tag.
  • tags.#.value - The value of the tag.
owners Sequence[str]
List of AMI owners to limit search. At least 1 value must be specified. Valid values: an AWS account ID, self (the current account), or an AWS owner alias (e.g., amazon, aws-marketplace, microsoft).
executable_users Sequence[str]
Limit search to users with explicit launch permission on the image. Valid items are the numeric account ID or self.
filters Sequence[GetAmiFilter]
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][1].
most_recent bool
If more than one result is returned, use the most recent AMI.
name_regex str
A 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. It is recommended to combine this with other options to narrow down the list AWS returns.
tags Mapping[str, str]

Any tags assigned to the image.

  • tags.#.key - The key name of the tag.
  • tags.#.value - The value of the tag.

getAmi Result

The following output properties are available:

Architecture string
The OS architecture of the AMI (ie: i386 or x86_64).
Arn string
The ARN of the AMI.
BlockDeviceMappings List<Pulumi.Aws.Ec2.Outputs.GetAmiBlockDeviceMapping>
Set of objects with block device mappings of the AMI.
CreationDate string
The date and time the image was created.
Description string
The description of the AMI that was provided during image creation.
EnaSupport bool
Specifies whether enhanced networking with ENA is enabled.
Hypervisor string
The hypervisor type of the image.
Id string
The provider-assigned unique ID for this managed resource.
ImageId string
The ID of the AMI. Should be the same as the resource id.
ImageLocation string
The location of the AMI.
ImageOwnerAlias string
The AWS account alias (for example, amazon, self) or the AWS account ID of the AMI owner.
ImageType string
The type of image.
KernelId string
The kernel associated with the image, if any. Only applicable for machine images.
Name string
The name of the AMI that was provided during image creation.
OwnerId string
The AWS account ID of the image owner.
Owners List<string>
Platform string
The value is Windows for Windows AMIs; otherwise blank.
PlatformDetails string
The platform details associated with the billing code of the AMI.
ProductCodes List<Pulumi.Aws.Ec2.Outputs.GetAmiProductCode>

Any product codes associated with the AMI.

  • product_codes.#.product_code_id - The product code.
  • product_codes.#.product_code_type - The type of product code.
Public bool
true if the image has public launch permissions.
RamdiskId string
The RAM disk associated with the image, if any. Only applicable for machine images.
RootDeviceName string
The device name of the root device.
RootDeviceType string
The type of root device (ie: ebs or instance-store).
RootSnapshotId string
The snapshot id associated with the root device, if any (only applies to ebs root devices).
SriovNetSupport string
Specifies whether enhanced networking is enabled.
State string
The current state of the AMI. If the state is available, the image is successfully registered and can be used to launch an instance.
StateReason Dictionary<string, string>

Describes a state change. Fields are UNSET if not available.

  • state_reason.code - The reason code for the state change.
  • state_reason.message - The message for the state change.
Tags Dictionary<string, string>

Any tags assigned to the image.

  • tags.#.key - The key name of the tag.
  • tags.#.value - The value of the tag.
UsageOperation string
The operation of the Amazon EC2 instance and the billing code that is associated with the AMI.
VirtualizationType string
The type of virtualization of the AMI (ie: hvm or paravirtual).
ExecutableUsers List<string>
Filters List<Pulumi.Aws.Ec2.Outputs.GetAmiFilter>
MostRecent bool
NameRegex string
Architecture string
The OS architecture of the AMI (ie: i386 or x86_64).
Arn string
The ARN of the AMI.
BlockDeviceMappings []GetAmiBlockDeviceMapping
Set of objects with block device mappings of the AMI.
CreationDate string
The date and time the image was created.
Description string
The description of the AMI that was provided during image creation.
EnaSupport bool
Specifies whether enhanced networking with ENA is enabled.
Hypervisor string
The hypervisor type of the image.
Id string
The provider-assigned unique ID for this managed resource.
ImageId string
The ID of the AMI. Should be the same as the resource id.
ImageLocation string
The location of the AMI.
ImageOwnerAlias string
The AWS account alias (for example, amazon, self) or the AWS account ID of the AMI owner.
ImageType string
The type of image.
KernelId string
The kernel associated with the image, if any. Only applicable for machine images.
Name string
The name of the AMI that was provided during image creation.
OwnerId string
The AWS account ID of the image owner.
Owners []string
Platform string
The value is Windows for Windows AMIs; otherwise blank.
PlatformDetails string
The platform details associated with the billing code of the AMI.
ProductCodes []GetAmiProductCode

Any product codes associated with the AMI.

  • product_codes.#.product_code_id - The product code.
  • product_codes.#.product_code_type - The type of product code.
Public bool
true if the image has public launch permissions.
RamdiskId string
The RAM disk associated with the image, if any. Only applicable for machine images.
RootDeviceName string
The device name of the root device.
RootDeviceType string
The type of root device (ie: ebs or instance-store).
RootSnapshotId string
The snapshot id associated with the root device, if any (only applies to ebs root devices).
SriovNetSupport string
Specifies whether enhanced networking is enabled.
State string
The current state of the AMI. If the state is available, the image is successfully registered and can be used to launch an instance.
StateReason map[string]string

Describes a state change. Fields are UNSET if not available.

  • state_reason.code - The reason code for the state change.
  • state_reason.message - The message for the state change.
Tags map[string]string

Any tags assigned to the image.

  • tags.#.key - The key name of the tag.
  • tags.#.value - The value of the tag.
UsageOperation string
The operation of the Amazon EC2 instance and the billing code that is associated with the AMI.
VirtualizationType string
The type of virtualization of the AMI (ie: hvm or paravirtual).
ExecutableUsers []string
Filters []GetAmiFilter
MostRecent bool
NameRegex string
architecture string
The OS architecture of the AMI (ie: i386 or x86_64).
arn string
The ARN of the AMI.
blockDeviceMappings GetAmiBlockDeviceMapping[]
Set of objects with block device mappings of the AMI.
creationDate string
The date and time the image was created.
description string
The description of the AMI that was provided during image creation.
enaSupport boolean
Specifies whether enhanced networking with ENA is enabled.
hypervisor string
The hypervisor type of the image.
id string
The provider-assigned unique ID for this managed resource.
imageId string
The ID of the AMI. Should be the same as the resource id.
imageLocation string
The location of the AMI.
imageOwnerAlias string
The AWS account alias (for example, amazon, self) or the AWS account ID of the AMI owner.
imageType string
The type of image.
kernelId string
The kernel associated with the image, if any. Only applicable for machine images.
name string
The name of the AMI that was provided during image creation.
ownerId string
The AWS account ID of the image owner.
owners string[]
platform string
The value is Windows for Windows AMIs; otherwise blank.
platformDetails string
The platform details associated with the billing code of the AMI.
productCodes GetAmiProductCode[]

Any product codes associated with the AMI.

  • product_codes.#.product_code_id - The product code.
  • product_codes.#.product_code_type - The type of product code.
public boolean
true if the image has public launch permissions.
ramdiskId string
The RAM disk associated with the image, if any. Only applicable for machine images.
rootDeviceName string
The device name of the root device.
rootDeviceType string
The type of root device (ie: ebs or instance-store).
rootSnapshotId string
The snapshot id associated with the root device, if any (only applies to ebs root devices).
sriovNetSupport string
Specifies whether enhanced networking is enabled.
state string
The current state of the AMI. If the state is available, the image is successfully registered and can be used to launch an instance.
stateReason {[key: string]: string}

Describes a state change. Fields are UNSET if not available.

  • state_reason.code - The reason code for the state change.
  • state_reason.message - The message for the state change.
tags {[key: string]: string}

Any tags assigned to the image.

  • tags.#.key - The key name of the tag.
  • tags.#.value - The value of the tag.
usageOperation string
The operation of the Amazon EC2 instance and the billing code that is associated with the AMI.
virtualizationType string
The type of virtualization of the AMI (ie: hvm or paravirtual).
executableUsers string[]
filters GetAmiFilter[]
mostRecent boolean
nameRegex string
architecture str
The OS architecture of the AMI (ie: i386 or x86_64).
arn str
The ARN of the AMI.
block_device_mappings Sequence[GetAmiBlockDeviceMapping]
Set of objects with block device mappings of the AMI.
creation_date str
The date and time the image was created.
description str
The description of the AMI that was provided during image creation.
ena_support bool
Specifies whether enhanced networking with ENA is enabled.
hypervisor str
The hypervisor type of the image.
id str
The provider-assigned unique ID for this managed resource.
image_id str
The ID of the AMI. Should be the same as the resource id.
image_location str
The location of the AMI.
image_owner_alias str
The AWS account alias (for example, amazon, self) or the AWS account ID of the AMI owner.
image_type str
The type of image.
kernel_id str
The kernel associated with the image, if any. Only applicable for machine images.
name str
The name of the AMI that was provided during image creation.
owner_id str
The AWS account ID of the image owner.
owners Sequence[str]
platform str
The value is Windows for Windows AMIs; otherwise blank.
platform_details str
The platform details associated with the billing code of the AMI.
product_codes Sequence[GetAmiProductCode]

Any product codes associated with the AMI.

  • product_codes.#.product_code_id - The product code.
  • product_codes.#.product_code_type - The type of product code.
public bool
true if the image has public launch permissions.
ramdisk_id str
The RAM disk associated with the image, if any. Only applicable for machine images.
root_device_name str
The device name of the root device.
root_device_type str
The type of root device (ie: ebs or instance-store).
root_snapshot_id str
The snapshot id associated with the root device, if any (only applies to ebs root devices).
sriov_net_support str
Specifies whether enhanced networking is enabled.
state str
The current state of the AMI. If the state is available, the image is successfully registered and can be used to launch an instance.
state_reason Mapping[str, str]

Describes a state change. Fields are UNSET if not available.

  • state_reason.code - The reason code for the state change.
  • state_reason.message - The message for the state change.
tags Mapping[str, str]

Any tags assigned to the image.

  • tags.#.key - The key name of the tag.
  • tags.#.value - The value of the tag.
usage_operation str
The operation of the Amazon EC2 instance and the billing code that is associated with the AMI.
virtualization_type str
The type of virtualization of the AMI (ie: hvm or paravirtual).
executable_users Sequence[str]
filters Sequence[GetAmiFilter]
most_recent bool
name_regex str

Supporting Types

GetAmiBlockDeviceMapping

DeviceName string
The physical name of the device.
Ebs Dictionary<string, string>
Map containing EBS information, if the device is EBS based. Unlike most object attributes, these are accessed directly (e.g., ebs.volume_size or ebs["volume_size"]) rather than accessed through the first element of a list (e.g., ebs[0].volume_size).
NoDevice string
Suppresses the specified device included in the block device mapping of the AMI.
VirtualName string
The virtual device name (for instance stores).
DeviceName string
The physical name of the device.
Ebs map[string]string
Map containing EBS information, if the device is EBS based. Unlike most object attributes, these are accessed directly (e.g., ebs.volume_size or ebs["volume_size"]) rather than accessed through the first element of a list (e.g., ebs[0].volume_size).
NoDevice string
Suppresses the specified device included in the block device mapping of the AMI.
VirtualName string
The virtual device name (for instance stores).
deviceName string
The physical name of the device.
ebs {[key: string]: string}
Map containing EBS information, if the device is EBS based. Unlike most object attributes, these are accessed directly (e.g., ebs.volume_size or ebs["volume_size"]) rather than accessed through the first element of a list (e.g., ebs[0].volume_size).
noDevice string
Suppresses the specified device included in the block device mapping of the AMI.
virtualName string
The virtual device name (for instance stores).
device_name str
The physical name of the device.
ebs Mapping[str, str]
Map containing EBS information, if the device is EBS based. Unlike most object attributes, these are accessed directly (e.g., ebs.volume_size or ebs["volume_size"]) rather than accessed through the first element of a list (e.g., ebs[0].volume_size).
no_device str
Suppresses the specified device included in the block device mapping of the AMI.
virtual_name str
The virtual device name (for instance stores).

GetAmiFilter

Name string
The name of the AMI that was provided during image creation.
Values List<string>
Name string
The name of the AMI that was provided during image creation.
Values []string
name string
The name of the AMI that was provided during image creation.
values string[]
name str
The name of the AMI that was provided during image creation.
values Sequence[str]

GetAmiProductCode

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.