createContainerRecipe

Creates a new container recipe. Container recipes define how images are configured, tested, and assessed.

Samples

// The following example creates a container recipe that customizes the Amazon EC2 instance that builds
// the container image. The build instance launches from an Amazon ECS optimized instance image and uses a
// 40 GiB gp3 volume.
val resp = imagebuilderClient.createContainerRecipe {
    containerType = ContainerType.fromValue("DOCKER")
    name = "my-example-container-recipe"
    semanticVersion = "1.1.0"
    description = "A container recipe that builds on an ECS-optimized instance image with a larger build volume"
    parentImage = "amazonlinux:latest"
    components = listOf<ComponentConfiguration>(
        ComponentConfiguration {
            componentArn = "arn:aws:imagebuilder:us-west-2:111122223333:component/my-example-container-component/1.0.0/1"
        }            
    )
    instanceConfiguration = InstanceConfiguration {
        image = "ami-1234567890abcdef0"
        blockDeviceMappings = listOf<InstanceBlockDeviceMapping>(
            InstanceBlockDeviceMapping {
                deviceName = "/dev/xvda"
                ebs = EbsInstanceBlockDeviceSpecification {
                    volumeSize = 40
                    volumeType = EbsVolumeType.fromValue("gp3")
                    deleteOnTermination = true
                }
            }                
        )
    }
    dockerfileTemplateData = "FROM {{{ imagebuilder:parentImage }}}\n{{{ imagebuilder:environments }}}\n{{{ imagebuilder:components }}}\n"
    targetRepository = TargetContainerRepository {
        service = ContainerRepositoryService.fromValue("ECR")
        repositoryName = "my-example-container-repo"
    }
    clientToken = "a1b2c3d4-5678-90ab-cdef-EXAMPLE40404"
}
// The following example creates a Docker container recipe that applies one build component, using the
// latest Amazon Linux container image as the parent and an existing ECR repository as the target.
val resp = imagebuilderClient.createContainerRecipe {
    containerType = ContainerType.fromValue("DOCKER")
    name = "my-example-container-recipe"
    semanticVersion = "1.0.0"
    parentImage = "amazonlinux:latest"
    components = listOf<ComponentConfiguration>(
        ComponentConfiguration {
            componentArn = "arn:aws:imagebuilder:us-west-2:111122223333:component/my-example-container-component/1.0.0/1"
        }            
    )
    dockerfileTemplateData = "FROM {{{ imagebuilder:parentImage }}}\n{{{ imagebuilder:environments }}}\n{{{ imagebuilder:components }}}\n"
    targetRepository = TargetContainerRepository {
        service = ContainerRepositoryService.fromValue("ECR")
        repositoryName = "my-example-container-repo"
    }
    clientToken = "a1b2c3d4-5678-90ab-cdef-EXAMPLE99999"
}