View a markdown version of this page

CreateInfrastructureConfiguration - EC2 Image Builder

CreateInfrastructureConfiguration

Creates a new infrastructure configuration. An infrastructure configuration defines the environment in which your image will be built and tested.

Request Syntax

PUT /CreateInfrastructureConfiguration HTTP/1.1 Content-type: application/json { "clientToken": "string", "description": "string", "dryRun": boolean, "instanceMetadataOptions": { "httpPutResponseHopLimit": number, "httpTokens": "string" }, "instanceProfileName": "string", "instanceTypes": [ "string" ], "keyPair": "string", "logging": { "s3Logs": { "s3BucketName": "string", "s3KeyPrefix": "string" } }, "name": "string", "placement": { "availabilityZone": "string", "hostId": "string", "hostResourceGroupArn": "string", "tenancy": "string" }, "resourceTags": { "string" : "string" }, "securityGroupIds": [ "string" ], "snsTopicArn": "string", "subnetId": "string", "tags": { "string" : "string" }, "terminateInstanceOnFailure": boolean }

URI Request Parameters

The request does not use any URI parameters.

Request Body

The request accepts the following data in JSON format.

clientToken

A unique, case-sensitive identifier you provide to ensure that the operation runs no more than one time. If you retry a request with the same client token, Image Builder returns the original response without running the operation again. For more information, see Ensuring idempotency in the Amazon EC2 API Reference.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 64.

Required: Yes

description

The description of the infrastructure configuration.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 1024.

Required: No

dryRun

Validates the required permissions and request parameters without performing the operation. If validation succeeds, the operation returns a DryRunOperationException error response.

Type: Boolean

Required: No

instanceMetadataOptions

The instance metadata service (IMDS) settings that Image Builder applies to the EC2 build and test instances it launches during image creation. If you don't set these options, the EC2 launch defaults for the instance apply. For more information about instance metadata options, see one of the following links:

Type: InstanceMetadataOptions object

Required: No

instanceProfileName

The instance profile to associate with the instance used to customize your Amazon EC2 AMI. The instance profile must exist in your account.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 256.

Pattern: ^[\w+=,.@-]+$

Required: Yes

instanceTypes

The instance types of the infrastructure configuration. You can specify one or more instance types to use for this build. Image Builder picks one of these instance types based on availability. If you don't specify instance types, Image Builder selects compatible instance types automatically. If you specify a Dedicated Host, Image Builder uses only instance types that the host supports.

Type: Array of strings

Required: No

keyPair

The key pair of the infrastructure configuration. You can use this to log on to and debug the instance used to create your image.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 1024.

Required: No

logging

The logging configuration of the infrastructure configuration. When you configure S3 logs, Image Builder writes logs from the build and test process to the specified bucket under the key prefix.

Type: Logging object

Required: No

name

The name of the infrastructure configuration. Infrastructure configuration names must be unique to your account in each AWS Region. Image Builder generates the infrastructure configuration ARN from a normalized form of the name, so names that differ only in case, spaces, or underscores count as the same name.

Type: String

Pattern: ^[-_A-Za-z-0-9][-_A-Za-z0-9 ]{1,126}[-_A-Za-z-0-9]$

Required: Yes

placement

The instance placement settings that define where the build and test instances that Image Builder launches during image creation run. These settings don't affect instances that you launch from the output image.

Type: Placement object

Required: No

resourceTags

The metadata tags to assign to the Amazon EC2 instance that Image Builder launches during the build process. Tags are formatted as key value pairs. Tag keys can't begin with aws: or match one of the following reserved keys: CreatedBy, Ec2ImageBuilderArn, Name, or Tags.

Type: String to string map

Map Entries: Maximum number of 30 items.

Key Length Constraints: Minimum length of 1. Maximum length of 128.

Key Pattern: ^(?!aws:)[a-zA-Z0-9\s_.:/=+\-@]*$

Value Length Constraints: Maximum length of 256.

Required: No

securityGroupIds

The security group IDs to associate with the instance used to customize your Amazon EC2 AMI.

Type: Array of strings

Length Constraints: Minimum length of 1. Maximum length of 1024.

Required: No

snsTopicArn

The Amazon Resource Name (ARN) of the SNS topic to which Image Builder sends image build event notifications. Specify a standard topic. Image Builder doesn't support FIFO topics. Image Builder validates the topic when you create or update the configuration. You must have permission to publish to the topic.

Note

EC2 Image Builder can't send notifications to SNS topics that are encrypted using keys from other accounts. If your SNS topic is encrypted, the key must be owned by the same account that owns your Image Builder resources.

Type: String

Pattern: ^arn:aws[^:]*:sns:[^:]+:[0-9]{12}:[a-zA-Z0-9-_]{1,256}$

Required: No

subnetId

The subnet ID in which to place the instance used to customize your Amazon EC2 AMI. If you specify subnetId, you must also specify one or more security group IDs in securityGroupIds. Otherwise, the request fails.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 1024.

Required: No

tags

The metadata tags to assign to the infrastructure configuration resource that Image Builder creates as output. Tags are formatted as key value pairs.

Type: String to string map

Map Entries: Maximum number of 50 items.

Key Length Constraints: Minimum length of 1. Maximum length of 128.

Key Pattern: ^(?!aws:)[a-zA-Z0-9\s_.:/=+\-@]*$

Value Length Constraints: Maximum length of 256.

Required: No

terminateInstanceOnFailure

Specifies whether to terminate the instance on failure. Set to false if you want Image Builder to retain the instance used to configure your AMI if the build or test phase of your workflow fails. Defaults to true.

Type: Boolean

Required: No

Response Syntax

HTTP/1.1 200 Content-type: application/json { "clientToken": "string", "infrastructureConfigurationArn": "string", "requestId": "string" }

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

clientToken

The client token that uniquely identifies the request.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 64.

infrastructureConfigurationArn

The Amazon Resource Name (ARN) of the infrastructure configuration that was created by this request.

Type: String

Pattern: ^arn:aws[^:]*:imagebuilder:[^:]+:(?:[0-9]{12}|aws):infrastructure-configuration/[a-z0-9-_]+$

requestId

The request ID that uniquely identifies this request.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 1024.

Errors

For information about the errors that are common to all actions, see Common Error Types.

CallRateLimitExceededException

You have exceeded the permitted request rate for the Amazon EC2 APIs that Image Builder calls on your behalf. Retry with an increasing or variable delay between requests.

HTTP Status Code: 429

ClientException

A generic client error. This error usually indicates that the request failed a validation check, such as when a downstream service rejects a configured value.

HTTP Status Code: 400

DryRunOperationException

The dry run operation of the resource was successful, and no resources or mutations were actually performed due to the dry run flag in the request.

HTTP Status Code: 412

ForbiddenException

You are not authorized to perform the requested operation.

HTTP Status Code: 403

IdempotentParameterMismatchException

You have specified a client token for an operation using parameter values that differ from a previous request that used the same client token.

HTTP Status Code: 400

InvalidRequestException

The request is malformed or otherwise invalid. Verify the request and try again.

HTTP Status Code: 400

ResourceAlreadyExistsException

The resource that you are trying to create already exists.

HTTP Status Code: 400

ResourceInUseException

The resource that you are trying to operate on is currently in use. Review the message details and retry later.

HTTP Status Code: 400

ServiceException

An internal server error occurred while Image Builder processed the request. Retrying the request may succeed.

HTTP Status Code: 500

ServiceQuotaExceededException

You have exceeded the number of permitted resources or operations for this service. For service quotas, see EC2 Image Builder endpoints and quotas.

HTTP Status Code: 402

ServiceUnavailableException

The service is unable to process your request at this time.

HTTP Status Code: 503

Examples

Create an infrastructure configuration

The following example creates an infrastructure configuration that gives Image Builder a choice of two instance types for its build and test instances.

Sample Request

PUT /CreateInfrastructureConfiguration HTTP/1.1 Content-type: application/json { "name": "my-example-infrastructure", "description": "An infrastructure configuration for Amazon Linux builds", "instanceProfileName": "EC2InstanceProfileForImageBuilder", "instanceTypes": ["t3.medium", "t3.large"], "terminateInstanceOnFailure": true, "clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE33333" }

Sample Response

HTTP/1.1 200 Content-type: application/json { "requestId": "67082698-415b-4d9f-8be0-84a58380b93f", "clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE33333", "infrastructureConfigurationArn": "arn:aws:imagebuilder:us-west-2:111122223333:infrastructure-configuration/my-example-infrastructure" }

Create an infrastructure configuration with instance placement and metadata options

The following example creates an infrastructure configuration. It places your build and test instances in a single Availability Zone and requires IMDSv2 for instance metadata requests. It also applies resource tags to the resources that Image Builder creates during the build.

Sample Request

PUT /CreateInfrastructureConfiguration HTTP/1.1 Content-type: application/json { "name": "my-example-infrastructure", "description": "An infrastructure configuration that pins build instances to one Availability Zone and requires IMDSv2", "instanceProfileName": "my-example-instance-role", "placement": { "availabilityZone": "us-west-2a" }, "instanceMetadataOptions": { "httpTokens": "required", "httpPutResponseHopLimit": 2 }, "resourceTags": { "CostCenter": "12345", "Environment": "test" }, "terminateInstanceOnFailure": true, "clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE98765" }

Sample Response

HTTP/1.1 200 Content-type: application/json { "requestId": "b96b54d8-daa6-4fdf-b25a-7b570bc2ab25", "clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE98765", "infrastructureConfigurationArn": "arn:aws:imagebuilder:us-west-2:111122223333:infrastructure-configuration/my-example-infrastructure" }

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: