Skip to content
v2.274.0

Experimental

@aws-cdk/aws-imagebuilder-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

Image L2 construct ​

Represents an EC2 Image Builder Image.

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
});
python
container_recipe = imagebuilder.ContainerRecipe(self, "MyContainerRecipe",
    base_image=imagebuilder.BaseContainerImage.from_docker_hub("amazonlinux", "latest"),
    target_repository=imagebuilder.Repository.from_ecr(
        ecr.Repository.from_repository_name(self, "Repository", "my-container-repo"))
)

container_image = imagebuilder.Image(self, "MyContainerImage",
    recipe=container_recipe
)
java
ContainerRecipe containerRecipe = ContainerRecipe.Builder.create(this, "MyContainerRecipe")
        .baseImage(BaseContainerImage.fromDockerHub("amazonlinux", "latest"))
        .targetRepository(Repository.fromEcr(Repository.fromRepositoryName(this, "Repository", "my-container-repo")))
        .build();

Image containerImage = Image.Builder.create(this, "MyContainerImage")
        .recipe(containerRecipe)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.AWS.ImageBuilder.Alpha
var containerRecipe = new ContainerRecipe(this, "MyContainerRecipe", new ContainerRecipeProps {
    BaseImage = BaseContainerImage.FromDockerHub("amazonlinux", "latest"),
    TargetRepository = Repository.FromEcr(Repository.FromRepositoryName(this, "Repository", "my-container-repo"))
});

var containerImage = new Image(this, "MyContainerImage", new ImageProps {
    Recipe = containerRecipe
});
go
// Install: go get github.com/aws/aws-cdk-go/awsimagebuilderalpha/v2
containerRecipe := imagebuilder.NewContainerRecipe(this, jsii.String("MyContainerRecipe"), &ContainerRecipeProps{
	BaseImage: imagebuilder.BaseContainerImage_*FromDockerHub(jsii.String("amazonlinux"), jsii.String("latest")),
	TargetRepository: imagebuilder.Repository_*FromEcr(ecr.Repository_*FromRepositoryName(this, jsii.String("Repository"), jsii.String("my-container-repo"))),
})

containerImage := imagebuilder.NewImage(this, jsii.String("MyContainerImage"), &ImageProps{
	Recipe: containerRecipe,
})

Initializer ​

ts
new Image(scope: Construct, id: string, props: ImageProps)
python
Image(scope: Construct, id: str, props: ImageProps)
java
new Image(Construct scope, String id, ImageProps props)
csharp
new Image(Construct scope, string id, ImageProps props)
go
NewImage(Scope Construct, Id *string, Props ImageProps)

Construct Props ​

deletionExecutionRoleIRoledeletion_execution_roleIRoledeletionExecutionRoleIRoleDeletionExecutionRoleIRoleDeletionExecutionRoleIRole#
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.

distributionConfigurationIDistributionConfigurationdistribution_configurationIDistributionConfigurationdistributionConfigurationIDistributionConfigurationDistributionConfigurationIDistributionConfigurationDistributionConfigurationIDistributionConfiguration= None#
The distribution configuration used for distributing the image.
enhancedImageMetadataEnabledbooleanenhanced_image_metadata_enabledboolenhancedImageMetadataEnabledBooleanEnhancedImageMetadataEnabledboolEnhancedImageMetadataEnabled*bool= true#
If enabled, collects additional information about the image being created, including the operating system (OS) version and package list for the AMI.
executionRoleIRoleexecution_roleIRoleexecutionRoleIRoleExecutionRoleIRoleExecutionRoleIRole#
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

notes

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.

imageScanningEcrRepositoryIRepositoryimage_scanning_ecr_repositoryIRepositoryimageScanningEcrRepositoryIRepositoryImageScanningEcrRepositoryIRepositoryImageScanningEcrRepositoryIRepository#
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.

imageScanningEcrTagsstring[]image_scanning_ecr_tagstyping.List[str]imageScanningEcrTagsList<String>ImageScanningEcrTagsstring[]ImageScanningEcrTags*[]*string= None#
The tags for Image Builder to apply to the output container image that Amazon Inspector scans.
imageScanningEnabledbooleanimage_scanning_enabledboolimageScanningEnabledBooleanImageScanningEnabledboolImageScanningEnabled*bool= 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.
imageTestsEnabledbooleanimage_tests_enabledboolimageTestsEnabledBooleanImageTestsEnabledboolImageTestsEnabled*bool= true#
Whether to run tests after building an image.
infrastructureConfigurationIInfrastructureConfigurationinfrastructure_configurationIInfrastructureConfigurationinfrastructureConfigurationIInfrastructureConfigurationInfrastructureConfigurationIInfrastructureConfigurationInfrastructureConfigurationIInfrastructureConfiguration#
The infrastructure configuration used for building the image.

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

notes

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.

logGroupILogGrouplog_groupILogGrouplogGroupILogGroupLogGroupILogGroupLogGroupILogGroup#
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>

recipeIRecipeBaserecipeIRecipeBaserecipeIRecipeBaseRecipeIRecipeBaseRecipeIRecipeBaserequired#
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 }tagstyping.Mapping[str, str]tagsMap<String, String>TagsIDictionary<string, string>Tags*map[string]*string= None#
The tags to apply to the image.
workflowsWorkflowConfiguration[]workflowstyping.List[WorkflowConfiguration]workflowsList<WorkflowConfiguration>WorkflowsWorkflowConfiguration[]Workflows*[]WorkflowConfiguration#
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 ​

The environment this resource belongs to.
notes

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.

executionRoleIRoleexecution_roleIRoleexecutionRoleIRoleExecutionRoleIRoleExecutionRoleIRole#
The execution role used for the image build.
imageArnstringimage_arnstrimageArnStringImageArnstringImageArn*stringrequired#
The ARN of the image.
imageIdstringimage_idstrimageIdStringImageIdstringImageId*stringrequired#
The AMI ID of the EC2 AMI, or URI for the container.
imageNamestringimage_namestrimageNameStringImageNamestringImageName*stringrequired#
The name of the image.
imageVersionstringimage_versionstrimageVersionStringImageVersionstringImageVersion*stringrequired#
The version of the image.
infrastructureConfigurationIInfrastructureConfigurationinfrastructure_configurationIInfrastructureConfigurationinfrastructureConfigurationIInfrastructureConfigurationInfrastructureConfigurationIInfrastructureConfigurationInfrastructureConfigurationIInfrastructureConfigurationrequired#
The infrastructure configuration used for the image build.
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.

Methods ​

applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

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

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

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@staticmethod def from_image_arn(scope: Construct, id: str, image_arn: str) -> IImagepublic static IImage fromImageArn(Construct scope, String id, String imageArn)public static IImage FromImageArn(Construct scope, string id, string imageArn)func FromImageArn(Scope Construct, Id *string, ImageArn *string) IImagestatic#
Import an existing image given its ARN.
fromImageAttributes(scope: Construct, id: string, attrs: ImageAttributes): IImage@staticmethod def from_image_attributes(scope: Construct, id: str, attrs: ImageAttributes) -> IImagepublic static IImage fromImageAttributes(Construct scope, String id, ImageAttributes attrs)public static IImage FromImageAttributes(Construct scope, string id, ImageAttributes attrs)func FromImageAttributes(Scope Construct, Id *string, Attrs ImageAttributes) IImagestatic#
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@staticmethod def from_image_name(scope: Construct, id: str, image_name: str) -> IImagepublic static IImage fromImageName(Construct scope, String id, String imageName)public static IImage FromImageName(Construct scope, string id, string imageName)func FromImageName(Scope Construct, Id *string, ImageName *string) IImagestatic#
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[]): Grantdef grant(self, grantee: IGrantable, actions: str) -> Grantpublic Grant grant(IGrantable grantee, String actions)public Grant Grant(IGrantable grantee, string actions)func Grant(Grantee IGrantable, Actions *string) Grant#
Grant custom actions to the given grantee for the image.

[disable-awslint:no-grants]

2 parameters

Parameters

  • granteegranteegranteegranteeGrantee — The principal.
  • actionsactionsactionsactionsActions — The list of actions.
grantDefaultExecutionRolePermissions(grantee: IGrantable): Grant[]def grant_default_execution_role_permissions(self, grantee: IGrantable) -> typing.List[Grant]public List<Grant> grantDefaultExecutionRolePermissions(IGrantable grantee)public Grant[] GrantDefaultExecutionRolePermissions(IGrantable grantee)func GrantDefaultExecutionRolePermissions(Grantee IGrantable) *[]Grant#
Grants the default permissions for building an image to the provided execution role.

[disable-awslint:no-grants]

1 parameter

Parameters

  • granteegranteegranteegranteeGrantee — The execution role used for the image build.
grantRead(grantee: IGrantable): Grantdef grant_read(self, grantee: IGrantable) -> Grantpublic Grant grantRead(IGrantable grantee)public Grant GrantRead(IGrantable grantee)func GrantRead(Grantee IGrantable) Grant#
Grant read permissions to the given grantee for the image.

[disable-awslint:no-grants]

1 parameter

Parameters

  • granteegranteegranteegranteeGrantee — The principal.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

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

  • xxxxX — Any object.

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

isImage(x: any): boolean@staticmethod def is_image(x: Any) -> boolpublic static Boolean isImage(Object x)public static bool IsImage(object x)func IsImage(X interface{}) *boolstatic#
Return whether the given object is an Image.
isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
toBaseImage(): BaseImagedef to_base_image(self, ) -> BaseImagepublic BaseImage toBaseImage()public BaseImage ToBaseImage()func ToBaseImage() BaseImage#
Converts the image to a BaseImage, to use as the parent image in an image recipe.
toContainerBaseImage(): BaseContainerImagedef to_container_base_image(self, ) -> BaseContainerImagepublic BaseContainerImage toContainerBaseImage()public BaseContainerImage ToContainerBaseImage()func ToContainerBaseImage() BaseContainerImage#
Converts the image to a ContainerBaseImage, to use as the parent image in a container recipe.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func 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.