AWS CDK ImageBuilder Construct Library

raw JSON →
1.204.0 verified Mon Apr 27 auth: no python maintenance

The CDK Construct Library for AWS::ImageBuilder provides high-level, object-oriented abstractions for defining and deploying EC2 Image Builder resources in AWS. The current version is 1.204.0, released as part of the AWS CDK v1, which is in maintenance mode. New development should use AWS CDK v2 and the @aws-cdk/aws-imagebuilder module.

pip install aws-cdk-aws-imagebuilder==1.204.0
error ModuleNotFoundError: No module named 'aws_cdk.aws_imagebuilder'
cause Using CDK v2 import path with v1 package installed.
fix
Either install CDK v2 (aws-cdk-lib) or use import path 'from aws_cdk.aws_imagebuilder import ...' in v1.
error AttributeError: module 'aws_cdk.aws_imagebuilder' has no attribute 'CfnImageRecipe'
cause Importing incorrectly, e.g., 'from aws_cdk.aws_imagebuilder.CfnImageRecipe import *'.
fix
Use correct import: 'from aws_cdk.aws_imagebuilder import CfnImageRecipe'.
error jsii.errors.JSIIError: .../aws-cdk-lib.aws-imagebuilder is not available
cause Mixing CDK v1 and v2 dependencies.
fix
Use only one version of CDK. For v1 use 'aws-cdk-aws-imagebuilder', for v2 use 'aws-cdk-lib' and remove v1 packages.
deprecated This is the CDK v1 package. CDK v1 entered maintenance mode on June 1, 2022 and will end support on June 1, 2023. Users should migrate to CDK v2 and use the @aws-cdk/aws-imagebuilder module instead.
fix Use 'aws-cdk-lib' and 'import aws_cdk.aws_imagebuilder as imagebuilder' in CDK v2.
breaking The CDK v1 and v2 packages have different names. In v1 it's 'aws-cdk-aws-imagebuilder', in v2 it's part of 'aws-cdk-lib' with imports from 'aws_cdk.aws_imagebuilder'.
fix Upgrade to CDK v2 and remove 'aws-cdk-aws-imagebuilder' from requirements. Use 'from aws_cdk import aws_imagebuilder as imagebuilder'.
gotcha Many Image Builder resources require ARNs of existing AWS resources (e.g., components, AMIs). Using dummy ARNs may cause deployment failures. Always reference valid ARNs or use tokens.
fix Ensure ARNs are valid. For components, use 'aws-cdk.aws_imagebuilder.CfnComponent' to create custom components or reference existing ones.
gotcha The property 'schedule' expects a ScheduleProperty object, not a cron expression string. Commonly mistaken.
fix Always wrap the schedule expression in a ScheduleProperty object as shown in the quickstart.

Creates a minimal CDK stack with an EC2 Image Builder image recipe, infrastructure configuration, and pipeline.

import aws_cdk as cdk
from aws_cdk import aws_imagebuilder as imagebuilder

app = cdk.App()
stack = cdk.Stack(app, "ImageBuilderStack")

# Create an Image Pipeline
image_recipe = imagebuilder.CfnImageRecipe(
    stack,
    "MyRecipe",
    name="my-recipe",
    version="1.0.0",
    parent_image="amazonlinux-2-x86_64",
    components=[
        imagebuilder.CfnImageRecipe.ComponentConfigurationProperty(
            component_arn="arn:aws:imagebuilder:us-east-1:aws:component/amazon-cloudwatch-agent/x.x.x"
        )
    ],
    working_directory="/tmp"
)

infra_config = imagebuilder.CfnInfrastructureConfiguration(
    stack,
    "MyInfraConfig",
    name="my-infra-config",
    instance_types=["t3.micro"],
    subnet_id="subnet-12345678"
)

pipeline = imagebuilder.CfnImagePipeline(
    stack,
    "MyPipeline",
    name="my-pipeline",
    image_recipe_arn=image_recipe.ref,
    infrastructure_configuration_arn=infra_config.ref,
    schedule=imagebuilder.CfnImagePipeline.ScheduleProperty(
        schedule_expression="cron(0 0 * * *)"
    )
)

app.synth()