Create custom images with Image Builder
There are several different ways that you can create a new Image Builder image. For example, you can use one of the following methods to create an image with the AWS Management Console or AWS CLI. You can also use the CreateImage API action or run a build pipeline to create the image. For the SDK request associated with the API action, you can refer to the See Also link for that command in the EC2 Image Builder API Reference.
- Console
-
To create a new image from an existing pipeline, you can manually run the pipeline, as follows. You can also use the pipeline wizard to create a new image from scratch. See Pipeline wizard: Create AMI or Pipeline wizard: Create container image, depending on the type of image you want to create.
-
Open the EC2 Image Builder console at https://console.aws.amazon.com/imagebuilder/
. -
Choose Image pipelines from the navigation pane.
-
Select the check box next to the Pipeline name that you want to run.
-
To create the image, select Run pipeline from the Actions menu. This starts the pipeline.
You can also specify a schedule to run your pipeline, or use Amazon EventBridge to run your pipeline based on rules that you configure.
-
- AWS CLI
-
Before you run the create-image
command in the AWS CLI, you must create the following resources if they don't already exist: Required resources
-
Recipe – You must specify exactly one recipe for your image, as follows:
- Image recipe
-
Specify the Amazon Resource Name (ARN) for your image recipe resource with the
--image-recipe-arnparameter. - Container recipe
-
Specify the ARN for your container recipe resource with the
--container-recipe-arnparameter.
-
Infrastructure configuration – Specify the ARN for your infrastructure configuration resource with the
--infrastructure-configuration-arnparameter.
You can also specify any of the following resources that your image requires:
Optional resources and configuration
-
Distribution configuration – By default, Image Builder distributes the output image resource to your account in the Region where you run the create-image command. To provide additional destinations or configuration for your distribution, specify the ARN for your distribution configuration resource with the
--distribution-configuration-arnparameter. -
Image scanning – To scan your image with Amazon Inspector during the test stage of the build, use the
--image-scanning-configurationparameter. By default, image scanning is off. For a test instance scan, Image Builder waits for Amazon Inspector to scan the test instance. For a container image scan, Image Builder pushes a copy of your container image to Amazon ECR for Amazon Inspector to scan. Image Builder then saves a snapshot of the findings with your image, so the findings remain available after the scanned resource no longer exists. For an on-demand AMI scan, Amazon Inspector scans the output AMI that the build creates, and the results appear in Amazon EC2. For more information about the scan types, see Amazon Inspector integration in Image Builder. If you specify a scanning configuration, the get-image response includes it, but image list responses don't. For an image that a pipeline builds, get-image returns the scanning configuration that the pipeline had when the build started. The get-image-pipeline and list-image-pipelines responses include the current scanning configuration of the pipeline. The--image-scanning-configurationparameter accepts the following fields:-
imageScanningEnabled (boolean) – Set to
trueto scan your image with Amazon Inspector during the test stage of the build. Set tofalse, or omit the field, to turn off scanning. You must set it totrueto useimageScanningTypesorscanResultCondition. -
ecrConfiguration (object) – Applies only to requests that specify a
containerRecipeArn. Sets the Amazon ECR repository and tags for the copy of the container image that Image Builder pushes for Amazon Inspector to scan. If you turn on scanning and specifyrepositoryNameorcontainerTagsinecrConfigurationfor a request that specifies animageRecipeArn, the request fails with anInvalidParameterCombinationException.-
repositoryName (string) – The name of an existing Amazon ECR repository for the scanned image, 1–1024 characters. For repository requirements, see Amazon Inspector integration in Image Builder. If you omit it, Image Builder uses
image-builder-image-scanning-repository, creates it if it doesn't exist, and removes the image after it collects the findings. The image stays in the repository if Image Builder doesn't finish collecting the findings, or if you name your own repository. -
containerTags (list of strings) – Additional tags that Image Builder applies to the container image that it pushes for scanning. Image Builder also applies its own version tags to that image. Each tag must be from 1–1024 characters in length.
-
-
imageScanningTypes (list of strings) – The type of scan. Specify exactly one value:
TEST_INSTANCE_CVEto scan the test instance, orON_DEMAND_AMI_CVEto scan the output AMI. You can't combine the two types. If you omit the field, Image Builder usesTEST_INSTANCE_CVEand saves that value in the scanning configuration.ON_DEMAND_AMI_CVEapplies only to requests that specify animageRecipeArn. For more information, see Scan output AMIs with on-demand AMI scans. -
scanResultCondition (object) – Optional. Applies only when
imageScanningTypesisON_DEMAND_AMI_CVE. Sets the most severe finding that the output AMI can have. If the AMI has a more severe finding, the image fails.-
maximumSeverityLabel (string) – Required. The most severe finding that the image can have. Valid values are
INFORMATIONAL,LOW,MEDIUM, andHIGH. A countedCRITICALfinding always fails the image. -
fixAvailable (boolean) – Set to
trueto count only findings that have a fix available. Set tofalseto count all findings. The default istrue. With the default, a severe finding that has no fix doesn't fail the image. If you omit the field, the get-image response shows it astrue.
-
Test stage requirements
If you turn on scanning and set
imageTestsEnabledtofalsein the--image-tests-configurationparameter, the request fails with anInvalidParameterCombinationException. This requirement applies to the create-image, create-image-pipeline, and update-image-pipeline commands.For
TEST_INSTANCE_CVEscans, if you use the--workflowsparameter, include exactly oneCollectImageScanFindingsstep across the test workflows for an image. Image Builder doesn't check for this step, and without it Image Builder saves no findings. The AWS managedexpress-test-imageworkflow doesn't include this step.On-demand AMI scan requirements
Image Builder rejects a request that sets
imageScanningTypestoON_DEMAND_AMI_CVEin the following cases:-
The request specifies a
containerRecipeArn. -
imageTestsEnabledisfalse. The request fails with anInvalidParameterCombinationException.
You don't need to specify an execution role. Without one, Image Builder runs the scan with its service-linked role, which includes the permissions that the scan needs. If you specify an execution role in the
--execution-roleparameter, the role must have these permissions. For the permissions, see Permissions for on-demand AMI scans.Image Builder adds the AWS managed
test-ami-scanworkflow to the image automatically. You don't need to list it in--workflows. For more information, see AMI scan managed workflow (test-ami-scan). -
-
Image tests – To suppress the Image Builder test stage, use the
--image-tests-configurationparameter. You can't setimageTestsEnabledtofalsewhen you enable image scanning. -
Image tags – Use the
--tagsparameter to add tags to your output image resource. -
Image workflows – If you don't specify any build or test workflows, Image Builder creates your image with its default image workflow. To specify workflows that you've created, use the
--workflowsparameter.Note
If you specify image workflows, you must also provide the name or ARN of the IAM role that Image Builder uses to run your workflow actions in the
--execution-roleparameter.
The following example shows how to create an image with the create-image
AWS CLI command. For more information, see the AWS CLI Command Reference. Example: Create a basic image with default distribution
aws imagebuilder create-image --image-recipe-arn arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/simple-recipe-linux/1.0.0--infrastructure-configuration-arn arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/simple-infra-config-linuxOutput:
{ "requestId": "1abcd234-e567-8fa9-0123-4567b890cd12", "imageVersionList": [ { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image/simple-recipe-linux/1.0.0", "name": "simple-recipe-linux", ... } ] }Example: Create an image with an on-demand AMI scan
The following example creates an image and requests an on-demand AMI scan of the output AMI. The image fails if the AMI has a finding with a fix available that's more severe than
HIGH. Save the following scanning configuration in a file namedscan-config.json:{ "imageScanningEnabled": true, "imageScanningTypes": ["ON_DEMAND_AMI_CVE"], "scanResultCondition": { "maximumSeverityLabel": "HIGH", "fixAvailable":true} }Replace the following values in the scanning configuration:
-
maximumSeverityLabel– The most severe finding to allow. Valid values areINFORMATIONAL,LOW,MEDIUM, andHIGH. A countedCRITICALfinding always fails the image. -
fixAvailable– Which findings to count. Entertrue(the default) to count only findings that have a fix available, orfalseto count every finding.
Then run the following AWS CLI command. Replace the Region, account ID, recipe, and infrastructure configuration names with your own values:
aws imagebuilder create-image \ --image-recipe-arn arn:aws:imagebuilder:us-west-2:111122223333:image-recipe/simple-recipe-linux/1.0.0\ --infrastructure-configuration-arn arn:aws:imagebuilder:us-west-2:111122223333:infrastructure-configuration/simple-infra-config-linux\ --image-tests-configuration imageTestsEnabled=true \ --image-scanning-configuration file://scan-config.json -
- PowerShell
-
The following example shows how to use the New-EC2IBImage cmdlet to create an image. This example uses default distribution settings:
New-EC2IBImage ` -ImageRecipeArn arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/simple-recipe-linux/1.0.0` -InfrastructureConfigurationArn arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/simple-infra-config-linux
Cancel image creation
- AWS CLI
-
To cancel an in-progress image build, use the cancel-image-creation command, as follows:
aws imagebuilder cancel-image-creation --image-build-version-arn arn:aws:imagebuilder:us-west-2:123456789012:image/my-example-recipe/2019.12.03/1 - PowerShell
-
The following example shows how to use the Stop-EC2IBImageCreation cmdlet to cancel an in-progress image build:
Stop-EC2IBImageCreation -ImageBuildVersionArn arn:aws:imagebuilder:us-west-2:123456789012:image/my-example-recipe/2019.12.03/1