Create a custom component with Image Builder
After you've completed your component document, you can use it to create a custom component that your Image Builder recipes can use. You can create a custom component from the Image Builder console, from the API or SDKs, or from the command line. For more information about how to create a custom component with input parameters and use it in your recipes, see Tutorial: Create a custom component with input parameters.
The following sections show you how to create components from the console or from the AWS CLI.
Contents
Create a custom component from the console
To create an AWSTOE application component from the Image Builder console, follow these steps:
-
Open the EC2 Image Builder console at https://console.aws.amazon.com/imagebuilder/
. -
Select Components from the navigation pane. Then select Create component.
-
On the Create component page, under Component details, enter the following:
-
Image Operating system (OS). Specify the operating system that the component is compatible with.
-
Component category. From the dropdown, select the type of build or test component that you are creating.
-
Component name. Enter a name for the component.
-
Component version. Enter the version number of the component.
-
Description. Provide an optional description to help you identify the component.
-
Change description. Provide an optional description to help you understand the changes made to this version of the component.
-
-
In the Definition document section, the default option is Define document content. The component document defines the actions that Image Builder performs on the build and test instances to create your image.
In the Content box, enter your YAML component document content. To start with a Hello World example for Linux, choose the Use example option. To learn more about how to create a YAML component document, or to copy and paste the UpdateOS example from that page, see Create a YAML component document for custom components in Image Builder.
-
After you enter the component details, select Create component.
Note
To see your new component when you create or update a recipe, apply the Owned by me filter to the build or test component list. The filter is located at the top of the component list, next to the search box.
-
To delete a component, from the Components page, select the check box next to the component that you want to delete. From the Actions dropdown, select Delete component.
Update a component
To create a new component version, follow these steps:
-
Depending on where you start:
-
From the Components list page – Select the check box next to the component name, then select Create new version from the Actions menu.
-
From the component detail page – Choose the Create new version button in the upper right corner of the heading.
-
-
The component information is already populated with the current values when the Create Component page displays. Follow the create a component steps to update the component. This ensures that you enter a unique semantic version in the Component version. To learn more about semantic versioning for Image Builder resources, see Semantic versioning in Image Builder.
Create a custom component from the AWS CLI
In this section, you'll learn how to set up and use Image Builder commands in the AWS CLI to create an AWSTOE application component, as follows.
-
Upload your YAML component document to an S3 bucket that you can reference from the command line.
-
Create the AWSTOE application component with the create-component command.
-
List component versions with the list-components command and a name filter to see what versions already exist. You can use the output to determine what the next version should be for updates.
To create an AWSTOE application component from an input YAML document, follow the steps that match your image operating system platform.
AWSTOE component versioning for updates from the AWS CLI
AWSTOE component names and versions are embedded in the component's Amazon Resource Name (ARN), after the component prefix. Each new version of a component has its own unique ARN. The steps to create a new version are exactly the same as the steps to create a new component, as long as the semantic version is unique for that component name. To learn more about semantic versioning for Image Builder resources, see Semantic versioning in Image Builder.
To ensure that you assign the next logical version, first get a list of the existing versions for the component that you want to change. Use the list-components command with the AWS CLI, and filter on the name.
In this example, you filter on the name of the component that you created in the
prior Linux examples. To list the component that you created, use the value of the
name
parameter from the JSON file that you used in the
create-component command.
aws imagebuilder list-components --filters name="name",values="
update-linux-os
"{ "requestId": "123a4567-b890-123c-45d6-ef789ab0cd1e", "componentVersionList": [ { "arn": "arn:aws:imagebuilder:us-west-2:1234560087789012:component/update-linux-os/1.0.0", "name": "update-linux-os", "version": "1.0.0", "platform": "Linux", "type": "BUILD", "owner": "123456789012", "dateCreated": "2020-09-24T16:58:24.444Z" }, { "arn": "arn:aws:imagebuilder:us-west-2:1234560087789012:component/update-linux-os/1.0.1", "name": "update-linux-os", "version": "1.0.1", "platform": "Linux", "type": "BUILD", "owner": "123456789012", "dateCreated": "2021-07-10T03:38:46.091Z" } ] }
Based on your results, you can determine what the next version should be.
Import a script to create a component from the AWS CLI
For some scenarios, it might be easier to start with a pre-existing script. For this scenario, you can use the following example.
This example assumes that you have a file called
(as shown). Note that the file directly references a PowerShell script called
import-component.json
AdminConfig.ps1
that is already uploaded to
. Currently,
amzn-s3-demo-source-bucket
SHELL
is supported for the component format
.
{ "name": "
MyImportedComponent
", "semanticVersion": "1.0.0", "description": "An example of how to import a component
", "changeDescription": "First commit message.
", "format": "SHELL", "platform": "Windows", "type": "BUILD", "uri": "s3://amzn-s3-demo-source-bucket
/AdminConfig.ps1
", "kmsKeyId": "arn:aws:kms:us-west-:key/
2:123456789012
60763706-b131-418b-8f85-3420912f020c
" }
To create the component from an imported script, run the following command.
aws imagebuilder import-component --cli-input-json file://
import-component.json