imagebuilder / Client / create_lifecycle_policy
create_lifecycle_policy¶
- imagebuilder.Client.create_lifecycle_policy(**kwargs)¶
Creates a lifecycle policy resource.
See also: AWS API Documentation
Request Syntax
response = client.create_lifecycle_policy( name='string', description='string', status='DISABLED'|'ENABLED', executionRole='string', resourceType='AMI_IMAGE'|'CONTAINER_IMAGE', policyDetails=[ { 'action': { 'type': 'DELETE'|'DEPRECATE'|'DISABLE', 'includeResources': { 'amis': True|False, 'snapshots': True|False, 'containers': True|False } }, 'filter': { 'type': 'AGE'|'COUNT', 'value': 123, 'unit': 'DAYS'|'WEEKS'|'MONTHS'|'YEARS', 'retainAtLeast': 123 }, 'exclusionRules': { 'tagMap': { 'string': 'string' }, 'amis': { 'isPublic': True|False, 'regions': [ 'string', ], 'sharedAccounts': [ 'string', ], 'lastLaunched': { 'value': 123, 'unit': 'DAYS'|'WEEKS'|'MONTHS'|'YEARS' }, 'tagMap': { 'string': 'string' } } } }, ], resourceSelection={ 'recipes': [ { 'name': 'string', 'semanticVersion': 'string' }, ], 'tagMap': { 'string': 'string' } }, tags={ 'string': 'string' }, clientToken='string', dryRun=True|False )
- Parameters:
name (string) –
[REQUIRED]
The name of the lifecycle policy to create. Policy names must be unique to your account in each Amazon Web Services 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.
description (string) – Optional description for the lifecycle policy.
status (string) – 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.executionRole (string) –
[REQUIRED]
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.
resourceType (string) –
[REQUIRED]
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.policyDetails (list) –
[REQUIRED]
Configuration details for the lifecycle policy rules. A policy can contain at most one rule per action type: one
DELETE, oneDEPRECATE, and oneDISABLE.(dict) –
Defines one lifecycle policy rule: the action to take, the filter that determines which resources the rule applies to, and optional exclusion rules.
action (dict) – [REQUIRED]
Configuration details for the policy action.
type (string) – [REQUIRED]
Specifies the lifecycle action to take.
DELETEdeletes the image resource and, withincludeResources, also removes distributed AMIs, snapshots, or container images.DEPRECATEandDISABLEset the corresponding status on the image resource and, ifincludeResources.amisis set, on its distributed AMIs.includeResources (dict) –
Specifies which underlying resources the action extends to beyond the Image Builder image resource itself: distributed AMIs, their snapshots, or distributed container images.
DELETErules can include all three,DEPRECATEandDISABLErules can include AMIs only, and you can only include snapshots together with AMIs.amis (boolean) –
Specifies whether the lifecycle action should apply to distributed AMIs.
snapshots (boolean) –
Specifies whether the lifecycle action should apply to snapshots associated with distributed AMIs.
containers (boolean) –
Specifies whether the lifecycle action should apply to distributed containers.
filter (dict) – [REQUIRED]
Specifies the resources that the lifecycle policy applies to.
type (string) – [REQUIRED]
Filter resources based on either
AGEorCOUNT. You can only use the count filter with theDELETEaction type.value (integer) – [REQUIRED]
The number of units for the time period or for the count. For example, a value of
6might refer to six months or six AMIs.Note
For count-based filters, this value represents the minimum number of resources to keep on hand. If you have fewer resources than this number, the resource is excluded from lifecycle actions.
unit (string) –
Defines the unit of time that the lifecycle policy uses to determine impacted resources. This is required for age-based rules.
retainAtLeast (integer) –
For age-based filters, this is the number of resources to keep on hand after the lifecycle
DELETEaction is applied. Impacted resources are only deleted if you have more than this number of resources. If you have fewer resources than this number, the impacted resource is not deleted.
exclusionRules (dict) –
Additional rules to specify resources that should be exempt from policy actions.
tagMap (dict) –
Contains a list of tags that Image Builder uses to skip lifecycle actions for Image Builder image resources that have them.
(string) –
(string) –
amis (dict) –
Lists configuration values that apply to AMIs that Image Builder should exclude from the lifecycle action.
isPublic (boolean) –
Configures whether public AMIs are excluded from the lifecycle action.
regions (list) –
Configures Amazon Web Services Regions that are excluded from the lifecycle action.
(string) –
sharedAccounts (list) –
The lifecycle action doesn’t apply to AMIs that are shared with any of the specified Amazon Web Services accounts.
(string) –
lastLaunched (dict) –
Configures Image Builder to exclude AMIs that were launched within the specified time period from lifecycle actions. AMIs with no recorded last-launched time aren’t excluded by this rule.
value (integer) – [REQUIRED]
The integer number of units for the time period. For example
6(months).unit (string) – [REQUIRED]
Defines the unit of time that the lifecycle policy uses to calculate elapsed time since the last launch.
tagMap (dict) –
Lifecycle actions don’t apply to AMIs that have any of these tags. Both the key and the value must match.
(string) –
(string) –
resourceSelection (dict) –
[REQUIRED]
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.
recipes (list) –
A list of recipes that are used as selection criteria for the output images that the lifecycle policy applies to.
(dict) –
Specifies an Image Builder recipe that the lifecycle policy uses for resource selection.
name (string) – [REQUIRED]
The name of an Image Builder recipe that the lifecycle policy uses for resource selection.
semanticVersion (string) – [REQUIRED]
The version of the Image Builder recipe specified by the
namefield.
tagMap (dict) –
A list of tags that are used as selection criteria for the Image Builder image resources that the lifecycle policy applies to.
(string) –
(string) –
tags (dict) –
Tags to apply to the lifecycle policy resource.
(string) –
(string) –
clientToken (string) –
[REQUIRED]
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.
This field is autopopulated if not provided.
dryRun (boolean) – Validates the required permissions and request parameters without performing the operation. If validation succeeds, the operation returns a
DryRunOperationExceptionerror response.
- Return type:
dict
- Returns:
Response Syntax
{ 'clientToken': 'string', 'lifecyclePolicyArn': 'string' }
Response Structure
(dict) –
clientToken (string) –
The client token that uniquely identifies the request.
lifecyclePolicyArn (string) –
The Amazon Resource Name (ARN) of the lifecycle policy that the request created.
Exceptions
imagebuilder.Client.exceptions.ServiceExceptionimagebuilder.Client.exceptions.ClientExceptionimagebuilder.Client.exceptions.ServiceUnavailableExceptionimagebuilder.Client.exceptions.InvalidRequestExceptionimagebuilder.Client.exceptions.IdempotentParameterMismatchExceptionimagebuilder.Client.exceptions.ForbiddenExceptionimagebuilder.Client.exceptions.CallRateLimitExceededExceptionimagebuilder.Client.exceptions.ResourceInUseExceptionimagebuilder.Client.exceptions.ResourceAlreadyExistsExceptionimagebuilder.Client.exceptions.ServiceQuotaExceededExceptionimagebuilder.Client.exceptions.DryRunOperationException