> **Experimental**
>
> `@aws-cdk/aws-imagebuilder-alpha` is an [**experimental**](/stability) (alpha) package: its API may change in any release, without a major version bump.
# Image

Represents an EC2 Image Builder Image.

Extends: Construct › Resource › Image
Implements: IImage, IResource, IEnvironmentAware, IConstruct, IDependable

- Stability: [Experimental](/cdk/api/stability.html)
- Source: [`lib/image.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0-alpha.0/packages/@aws-cdk/aws-imagebuilder-alpha/lib/image.ts#L340)

## Example

```ts
const containerRecipe = new imagebuilder.ContainerRecipe(this, 'MyContainerRecipe', {
  baseImage: imagebuilder.BaseContainerImage.fromDockerHub('amazonlinux', 'latest'),
  targetRepository: imagebuilder.Repository.fromEcr(
    ecr.Repository.fromRepositoryName(this, 'Repository', 'my-container-repo')
  )
});

const containerImage = new imagebuilder.Image(this, 'MyContainerImage', {
  recipe: containerRecipe
});
```

## Initializer

```ts
new Image(scope: Construct, id: string, props: ImageProps)
```

## Construct Props

- `deletionExecutionRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The execution role to use for deleting the image as well as the underlying resources, such as the AMIs, snapshots, and containers.

  **Default:** no execution role. Only the Image Builder image will be deleted.

  This role should contain resource lifecycle permissions required to delete the underlying
  AMIs/containers.

- `distributionConfiguration`: [IDistributionConfiguration](/cdk/api/v2/docs/@aws-cdk_aws-imagebuilder-alpha.IDistributionConfiguration.html) = None — The distribution configuration used for distributing the image.

- `enhancedImageMetadataEnabled`: boolean = true — If enabled, collects additional information about the image being created, including the operating system (OS) version and package list for the AMI.

- `executionRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The execution role used to perform workflow actions to build the image.

  **Default:** Image Builder will use the SLR if possible. Otherwise, an execution role will be generated

  By default, the Image Builder Service Linked Role (SLR) will be created automatically and used as the execution
  role. However, when providing a custom set of image workflows for the image, an execution role will be
  generated with the minimal permissions needed to execute the workflows.

- `imageScanningEcrRepository`: [IRepository](/cdk/api/v2/docs/aws-cdk-lib.aws_ecr.IRepository.html) — The container repository that Amazon Inspector scans to identify findings for your container images.

  **Default:** if scanning is enabled, a repository will be created by Image Builder if one is not provided

  If a
  repository is not provided, Image Builder creates a repository named `image-builder-image-scanning-repository`
  for vulnerability scanning.

- `imageScanningEcrTags`: string[] = None — The tags for Image Builder to apply to the output container image that Amazon Inspector scans.

- `imageScanningEnabled`: boolean = false — Indicates whether Image Builder keeps a snapshot of the vulnerability scans that Amazon Inspector runs against the build instance when you create a new image.

- `imageTestsEnabled`: boolean = true — Whether to run tests after building an image.

- `infrastructureConfiguration`: [IInfrastructureConfiguration](/cdk/api/v2/docs/@aws-cdk_aws-imagebuilder-alpha.IInfrastructureConfiguration.html) — The infrastructure configuration used for building the image.

  **Default:** an infrastructure configuration will be created with the default settings

  A default infrastructure configuration will be used if one is not provided.

  The default configuration will create an instance profile and role with minimal permissions needed to build the
  image, attached to the EC2 instance.

  IMDSv2 will be required by default on the instances used to build and test the image.

- `logGroup`: [ILogGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_logs.ILogGroup.html) — The log group to use for the image.

  **Default:** a log group will be created

  By default, a log group will be created with the format
  `/aws/imagebuilder/<image-name>`

- `recipe`: [IRecipeBase](/cdk/api/v2/docs/@aws-cdk_aws-imagebuilder-alpha.IRecipeBase.html) (required) — The recipe that defines the base image, components, and customizations used to build the image.

  This can either be
  an image recipe, or a container recipe.

- `tags`: { [key: string]: string } = None — The tags to apply to the image.

- `workflows`: [WorkflowConfiguration](/cdk/api/v2/docs/@aws-cdk_aws-imagebuilder-alpha.WorkflowConfiguration.html)[] — The list of workflow configurations used to build the image.

  **Default:** Image Builder will use a default set of workflows for the build to build, test, and distribute the image

## Properties

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `executionRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The execution role used for the image build.

- `imageArn`: string — The ARN of the image.

- `imageId`: string — The AMI ID of the EC2 AMI, or URI for the container.

- `imageName`: string — The name of the image.

- `imageVersion`: string — The version of the image.

- `infrastructureConfiguration`: [IInfrastructureConfiguration](/cdk/api/v2/docs/@aws-cdk_aws-imagebuilder-alpha.IInfrastructureConfiguration.html) — The infrastructure configuration used for the image build.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this resource is defined.

## Methods

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `fromImageArn(scope: Construct, id: string, imageArn: string): IImage` (static) — Import an existing image given its ARN.

- `fromImageAttributes(scope: Construct, id: string, attrs: ImageAttributes): IImage` (static) — Import an existing image by providing its attributes.

  If the image name is provided as an attribute, it must be
  normalized by converting all alphabetical characters to lowercase, and replacing all spaces and underscores with
  hyphens.

- `fromImageName(scope: Construct, id: string, imageName: string): IImage` (static) — Import an existing image given its name.

  The provided name must be normalized by converting all alphabetical
  characters to lowercase, and replacing all spaces and underscores with hyphens.

- `grant(grantee: IGrantable, ...actions: string[]): Grant` — Grant custom actions to the given grantee for the image.

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — The principal.
  - `actions` — The list of actions.

- `grantDefaultExecutionRolePermissions(grantee: IGrantable): Grant[]` — Grants the default permissions for building an image to the provided execution role.

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — The execution role used for the image build.

- `grantRead(grantee: IGrantable): Grant` — Grant read permissions to the given grantee for the image.

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — The principal.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isImage(x: any): boolean` (static) — Return whether the given object is an Image.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `toBaseImage(): BaseImage` — Converts the image to a BaseImage, to use as the parent image in an image recipe.

- `toContainerBaseImage(): BaseContainerImage` — Converts the image to a ContainerBaseImage, to use as the parent image in a container recipe.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
