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

Represents an EC2 Image Builder Container Recipe.

Extends: Construct › Resource › ContainerRecipeBase › ContainerRecipe
Implements: IContainerRecipe, IRecipeBase, IResource, IEnvironmentAware, IConstruct, IDependable

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

## 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 containerPipeline = new imagebuilder.ImagePipeline(this, 'MyContainerPipeline', {
  recipe: exampleContainerRecipe
});
```

## Initializer

```ts
new ContainerRecipe(scope: Construct, id: string, props: ContainerRecipeProps)
```

## Construct Props

- `baseImage`: [BaseContainerImage](/cdk/api/v2/docs/@aws-cdk_aws-imagebuilder-alpha.BaseContainerImage.html) (required) — The base image for customizations specified in the container recipe.

- `components`: [ComponentConfiguration](/cdk/api/v2/docs/@aws-cdk_aws-imagebuilder-alpha.ComponentConfiguration.html)[] = None — The list of component configurations to apply in the image build.

- `containerRecipeName`: string — The name of the container recipe.

  **Default:** a name is generated

- `containerRecipeVersion`: string = 1.0.x — The version of the container recipe.

- `description`: string = None — The description of the container recipe.

- `dockerfile`: [DockerfileData](/cdk/api/v2/docs/@aws-cdk_aws-imagebuilder-alpha.DockerfileData.html) — The dockerfile template used to build the container image.

  **Default:** a standard dockerfile template will be generated to pull the base image, perform environment setup, and run all components in the recipe

- `instanceBlockDevices`: [BlockDevice](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.BlockDevice.html)[] — The block devices to attach to the instance used for building, testing, and distributing the container image.

  **Default:** the block devices of the instance image will be used

- `instanceImage`: [ContainerInstanceImage](/cdk/api/v2/docs/@aws-cdk_aws-imagebuilder-alpha.ContainerInstanceImage.html) — The image to use to launch the instance used for building, testing, and distributing the container image.

  **Default:** Image Builder will use the appropriate ECS-optimized AMI

- `kmsKey`: [IKey](/cdk/api/v2/docs/aws-cdk-lib.aws_kms.IKey.html) = None — The KMS key used to encrypt the dockerfile template.

- `osVersion`: [OSVersion](/cdk/api/v2/docs/@aws-cdk_aws-imagebuilder-alpha.OSVersion.html) — The operating system (OS) version of the base image.

  **Default:** Image Builder will determine the OS version of the base image, if sourced from a third-party container registry. Otherwise, the OS version of the base image is required.

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

- `targetRepository`: [Repository](/cdk/api/v2/docs/@aws-cdk_aws-imagebuilder-alpha.Repository.html) (required) — The container repository where the output container image is stored.

- `workingDirectory`: string — The working directory for use during build and test workflows.

  **Default:** the Image Builder default working directory is used. For Linux and macOS builds, this would be /tmp. For Windows builds, this would be C:/

## Properties

- `containerRecipeArn`: string — The ARN of the container recipe.

- `containerRecipeName`: string — The name of the container recipe.

- `containerRecipeVersion`: string — The version of the container recipe.

- `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.

- `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

- `addInstanceBlockDevice(...instanceBlockDevices: BlockDevice[]): void` — Adds block devices to attach to the instance used for building, testing, and distributing the container image.

  **Parameters**

  - `instanceBlockDevices` — - The list of block devices to attach.

- `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`).

- `fromContainerRecipeArn(scope: Construct, id: string, containerRecipeArn: string): IContainerRecipe` (static) — Import an existing container recipe given its ARN.

- `fromContainerRecipeAttributes(scope: Construct, id: string, attrs: ContainerRecipeAttributes): IContainerRecipe` (static) — Import an existing container recipe by providing its attributes.

  If the container recipe 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.

- `fromContainerRecipeName(scope: Construct, id: string, containerRecipeName: string): IContainerRecipe` (static) — Import the latest version of an existing container recipe 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 container recipe [disable-awslint:no-grants].

  **Parameters**

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

- `grantRead(grantee: IGrantable): Grant` — Grant read permissions to the given grantee for the container recipe [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`.

- `isContainerRecipe(x: any): boolean` (static) — Return whether the given object is a ContainerRecipe.

- `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.

- `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.
