# LookupMachineImage

A machine image whose AMI ID will be searched 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.
If `props.additionalCacheKey` is set, the context key uses that value as a discriminator
rather than the cached value being global across all lookups.

Implements: [IMachineImage](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IMachineImage.html)
Superclass of: [NatInstanceImage](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.NatInstanceImage.html)

- Source: [`aws-ec2/lib/machine-image/machine-image.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-ec2/lib/machine-image/machine-image.ts#L691)

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_ec2 as ec2 } from 'aws-cdk-lib';

declare const userData: ec2.UserData;
const lookupMachineImage = new ec2.LookupMachineImage({
  name: 'name',

  // the properties below are optional
  additionalCacheKey: 'additionalCacheKey',
  filters: {
    filtersKey: ['filters'],
  },
  owners: ['owners'],
  userData: userData,
  windows: false,
});
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_ec2 as ec2

# user_data: ec2.UserData

lookup_machine_image = ec2.LookupMachineImage(
    name="name",

    # the properties below are optional
    additional_cache_key="additionalCacheKey",
    filters={
        "filters_key": ["filters"]
    },
    owners=["owners"],
    user_data=user_data,
    windows=False
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.ec2.*;

UserData userData;

LookupMachineImage lookupMachineImage = LookupMachineImage.Builder.create()
        .name("name")

        // the properties below are optional
        .additionalCacheKey("additionalCacheKey")
        .filters(Map.of(
                "filtersKey", List.of("filters")))
        .owners(List.of("owners"))
        .userData(userData)
        .windows(false)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.EC2;

UserData userData;

var lookupMachineImage = new LookupMachineImage(new LookupMachineImageProps {
    Name = "name",

    // the properties below are optional
    AdditionalCacheKey = "additionalCacheKey",
    Filters = new Dictionary<string, string[]> {
        { "filtersKey", new [] { "filters" } }
    },
    Owners = new [] { "owners" },
    UserData = userData,
    Windows = false
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

var userData UserData

lookupMachineImage := awscdk.Aws_ec2.NewLookupMachineImage(&LookupMachineImageProps{
	Name: jsii.String("name"),

	// the properties below are optional
	AdditionalCacheKey: jsii.String("additionalCacheKey"),
	Filters: map[string][]*string{
		"filtersKey": []*string{
			jsii.String("filters"),
		},
	},
	Owners: []*string{
		jsii.String("owners"),
	},
	UserData: userData,
	Windows: jsii.Boolean(false),
})
```

## Initializer

TypeScript:

```ts
new LookupMachineImage(props: LookupMachineImageProps)
```

Python:

```python
LookupMachineImage(props: LookupMachineImageProps)
```

Java:

```java
new LookupMachineImage(LookupMachineImageProps props)
```

C# / .NET:

```csharp
new LookupMachineImage(LookupMachineImageProps props)
```

Golang:

```go
NewLookupMachineImage(Props LookupMachineImageProps)
```

## Methods

- `getImage(scope: Construct): MachineImageConfig` — Return the correct image.
