create_lifecycle_policy
¶
create_lifecycle_policy(
name: ResourceName,
execution_role: RoleNameOrArn,
resource_type: LifecyclePolicyResourceType,
policy_details: LifecyclePolicyDetails,
resource_selection: LifecyclePolicyResourceSelection,
client_token: ClientToken,
*,
config_overrides: Optional[imagebuilderClientConfig] = None,
description: Optional[NonEmptyString] = None,
status: Optional[LifecyclePolicyStatus] = None,
tags: Optional[TagMap] = None,
dry_run: Optional[Boolean] = None,
) -> CreateLifecyclePolicyResponse
Creates a lifecycle policy resource.
Parameters:
-
name(ResourceName) –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(Optional[NonEmptyString], default:None) –Optional description for the lifecycle policy.
-
status(Optional[LifecyclePolicyStatus], default:None) –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. -
execution_role(RoleNameOrArn) –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.
-
resource_type(LifecyclePolicyResourceType) –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. -
policy_details(LifecyclePolicyDetails) –Configuration details for the lifecycle policy rules. A policy can contain at most one rule per action type: one
DELETE, oneDEPRECATE, and oneDISABLE. -
resource_selection(LifecyclePolicyResourceSelection) –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.
-
tags(Optional[TagMap], default:None) –Tags to apply to the lifecycle policy resource.
-
client_token(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.
-
dry_run(Optional[Boolean], default:None) –Validates the required permissions and request parameters without performing the operation. If validation succeeds, the operation returns a
DryRunOperationExceptionerror response.
Raises:
-
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.
-
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.
-
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.
-
ForbiddenException–You are not authorized to perform the requested operation.
-
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.
-
InvalidRequestException–The request is malformed or otherwise invalid. Verify the request and try again.
-
ResourceAlreadyExistsException–The resource that you are trying to create already exists.
-
ResourceInUseException–The resource that you are trying to operate on is currently in use. Review the message details and retry later.
-
ServiceException–An internal server error occurred while Image Builder processed the request. Retrying the request may succeed.
-
ServiceQuotaExceededException–You have exceeded the number of permitted resources or operations for this service. For service quotas, see EC2 Image Builder endpoints and quotas.
-
ServiceUnavailableException–The service is unable to process your request at this time.
-
UnknownServiceError–The service returned an error code this client does not model.
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.
>>> client.create_lifecycle_policy(name='my-example-lifecycle-policy', execution_role='arn:aws:iam::111122223333:role/my-example-lifecycle-role', resource_type='AMI_IMAGE', policy_details=[{'action': {'type': 'DELETE'}, 'filter': {'type': 'AGE', 'value': 6, 'unit': 'MONTHS'}}], resource_selection={'tagMap': {'Environment': 'test'}}, client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE13579')
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.
>>> client.create_lifecycle_policy(name='my-example-lifecycle-policy', execution_role='arn:aws:iam::111122223333:role/my-example-lifecycle-role', resource_type='AMI_IMAGE', policy_details=[{'action': {'type': 'DELETE'}, 'filter': {'type': 'AGE', 'value': 6, 'unit': 'MONTHS'}, 'exclusionRules': {'amis': {'lastLaunched': {'value': 30, 'unit': 'DAYS'}, 'tagMap': {'Retention': 'keep'}}}}], resource_selection={'recipes': [{'name': 'my-example-recipe', 'semanticVersion': '1.0.0'}]}, client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLE43210')
Source code in docs_src/capo_imagebuilder/_services/imagebuilder.py
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 | |