CreateLifecyclePolicy
Creates a lifecycle policy resource.
Request Syntax
PUT /CreateLifecyclePolicy HTTP/1.1
Content-type: application/json
{
"clientToken": "string",
"description": "string",
"dryRun": boolean,
"executionRole": "string",
"name": "string",
"policyDetails": [
{
"action": {
"includeResources": {
"amis": boolean,
"containers": boolean,
"snapshots": boolean
},
"type": "string"
},
"exclusionRules": {
"amis": {
"isPublic": boolean,
"lastLaunched": {
"unit": "string",
"value": number
},
"regions": [ "string" ],
"sharedAccounts": [ "string" ],
"tagMap": {
"string" : "string"
}
},
"tagMap": {
"string" : "string"
}
},
"filter": {
"retainAtLeast": number,
"type": "string",
"unit": "string",
"value": number
}
}
],
"resourceSelection": {
"recipes": [
{
"name": "string",
"semanticVersion": "string"
}
],
"tagMap": {
"string" : "string"
}
},
"resourceType": "string",
"status": "string",
"tags": {
"string" : "string"
}
}
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
-
Optional description for the lifecycle policy.
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
DryRunOperationExceptionerror response.Type: Boolean
Required: No
- executionRole
-
The name or Amazon Resource Name (ARN) for the IAM role you create that grants Image Builder access to run lifecycle actions. You must have permission to pass the role, and the role's trust policy must allow the Image Builder service principal to assume it.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 2048.
Pattern:
^(?:arn:aws(?:-[a-z]+)*:iam::[0-9]{12}:role/)?[a-zA-Z_0-9+=,.@\-_/]+$Required: Yes
- name
-
The name of the lifecycle policy to create. Policy names must be unique to your account in each AWS Region. Image Builder generates the policy ARN from a normalized form of the name, so names that differ only in case, spaces, or underscores count as the same name. You can't change the name after creation.
Type: String
Pattern:
^[-_A-Za-z-0-9][-_A-Za-z0-9 ]{1,126}[-_A-Za-z-0-9]$Required: Yes
- policyDetails
-
Configuration details for the lifecycle policy rules. A policy can contain at most one rule per action type: one
DELETE, oneDEPRECATE, and oneDISABLE.Type: Array of LifecyclePolicyDetail objects
Array Members: Minimum number of 1 item. Maximum number of 3 items.
Required: Yes
- resourceSelection
-
Selection criteria for the resources that the lifecycle policy applies to. You must specify exactly one selection criteria: either recipes or a tag map, not both.
Type: LifecyclePolicyResourceSelection object
Required: Yes
- resourceType
-
The type of Image Builder resource that the lifecycle policy applies to. The resource type determines the allowed rule actions: policies for AMI-based Image Builder images support
DELETE,DEPRECATE, andDISABLE, and policies for container-based Image Builder images support onlyDELETE. You can't change the resource type after creation.Type: String
Valid Values:
AMI_IMAGE | CONTAINER_IMAGERequired: Yes
- status
-
Indicates whether the lifecycle policy resource is enabled. If you don't specify a status, it defaults to
ENABLED. Only enabled policies run on their schedule.Type: String
Valid Values:
DISABLED | ENABLEDRequired: No
-
Tags to apply to the lifecycle policy resource.
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
Response Syntax
HTTP/1.1 200
Content-type: application/json
{
"clientToken": "string",
"lifecyclePolicyArn": "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.
- lifecyclePolicyArn
-
The Amazon Resource Name (ARN) of the lifecycle policy that the request created.
Type: String
Length Constraints: Maximum length of 1024.
Pattern:
^arn:aws(?:-[a-z]+)*:imagebuilder:[a-z]{2,}(?:-[a-z]+)+-[0-9]+:(?:[0-9]{12}|aws):lifecycle-policy/[a-z0-9-_]+$
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 a lifecycle policy
The following example creates a lifecycle policy that deletes AMI-based images six months after they were created, selecting the images that match the specified resource tags.
Sample Request
PUT /CreateLifecyclePolicy HTTP/1.1
Content-type: application/json
{
"name": "my-example-lifecycle-policy",
"executionRole": "arn:aws:iam::111122223333:role/my-example-lifecycle-role",
"resourceType": "AMI_IMAGE",
"policyDetails": [
{
"action": {
"type": "DELETE"
},
"filter": {
"type": "AGE",
"value": 6,
"unit": "MONTHS"
}
}
],
"resourceSelection": {
"tagMap": {
"Environment": "test"
}
},
"clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE13579"
}
Sample Response
HTTP/1.1 200
Content-type: application/json
{
"clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE13579",
"lifecyclePolicyArn": "arn:aws:imagebuilder:us-west-2:111122223333:lifecycle-policy/my-example-lifecycle-policy"
}
Create a lifecycle policy with exclusion rules
The following example creates a lifecycle policy that deletes images created from the specified recipe version after six months. The policy excludes images whose AMIs launched an instance within the last 30 days or are tagged to be retained.
Sample Request
PUT /CreateLifecyclePolicy HTTP/1.1
Content-type: application/json
{
"name": "my-example-lifecycle-policy",
"executionRole": "arn:aws:iam::111122223333:role/my-example-lifecycle-role",
"resourceType": "AMI_IMAGE",
"policyDetails": [
{
"action": {
"type": "DELETE"
},
"filter": {
"type": "AGE",
"value": 6,
"unit": "MONTHS"
},
"exclusionRules": {
"amis": {
"lastLaunched": {
"value": 30,
"unit": "DAYS"
},
"tagMap": {
"Retention": "keep"
}
}
}
}
],
"resourceSelection": {
"recipes": [
{
"name": "my-example-recipe",
"semanticVersion": "1.0.0"
}
]
},
"clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE43210"
}
Sample Response
HTTP/1.1 200
Content-type: application/json
{
"clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE43210",
"lifecyclePolicyArn": "arn:aws:imagebuilder:us-west-2:111122223333:lifecycle-policy/my-example-lifecycle-policy"
}
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: