Skip to content

update_lifecycle_policy

update_lifecycle_policy(
    lifecycle_policy_arn: LifecyclePolicyArn,
    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,
) -> UpdateLifecyclePolicyResponse

Updates the specified lifecycle policy. The request replaces the existing policy configuration rather than merging changes, so re-specify every setting that you want to keep. The resourceType must match the existing policy's value.

Parameters:

  • lifecycle_policy_arn (LifecyclePolicyArn) –

    The Amazon Resource Name (ARN) of the lifecycle policy resource.

  • description (Optional[NonEmptyString], default: None ) –

    Optional description for the lifecycle policy. Because the update replaces the entire configuration, omitting this property removes any existing description.

  • status (Optional[LifecyclePolicyStatus], default: None ) –

    Indicates whether the lifecycle policy resource is enabled. Defaults to ENABLED when omitted, so updating a disabled policy without setting this property re-enables it.

  • 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.

  • resource_type (LifecyclePolicyResourceType) –

    The type of image resource that the lifecycle policy applies to. The value must match the policy's existing resource type. You can't change the resource type of an existing lifecycle policy.

  • policy_details (LifecyclePolicyDetails) –

    The configuration details for a lifecycle policy resource.

  • resource_selection (LifecyclePolicyResourceSelection) –

    Selection criteria for resources that the lifecycle policy applies to. You must specify exactly one selection criteria: either recipes or a tag map, not both.

  • 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.

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.

  • 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.

  • InvalidParameterCombinationException –

    You have specified a combination of parameters that isn't valid. For example, two mutually exclusive parameters, or a parameter without its required companion parameter. Review the error message for details.

  • InvalidRequestException –

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

  • 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.

  • 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:

Update a lifecycle policy The following example updates a lifecycle policy to delete AMI images and their associated snapshots after 12 months, retaining the 3 most recent images.

>>> client.update_lifecycle_policy(lifecycle_policy_arn='arn:aws:imagebuilder:us-west-2:111122223333:lifecycle-policy/my-example-policy', description='Deletes AMI images and their snapshots after 12 months, retaining the 3 most recent', status='ENABLED', execution_role='arn:aws:iam::111122223333:role/my-example-lifecycle-role', resource_type='AMI_IMAGE', policy_details=[{'action': {'type': 'DELETE', 'includeResources': {'amis': True, 'snapshots': True}}, 'filter': {'type': 'AGE', 'value': 12, 'unit': 'MONTHS', 'retainAtLeast': 3}}], resource_selection={'tagMap': {'environment': 'production'}}, client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLEaaaaa')
Source code in docs_src/capo_imagebuilder/_services/imagebuilder.py
def update_lifecycle_policy(
    self,
    lifecycle_policy_arn: "capo_imagebuilder.types.lifecycle_policy_arn.LifecyclePolicyArn",
    execution_role: "capo_imagebuilder.types.role_name_or_arn.RoleNameOrArn",
    resource_type: "capo_imagebuilder.types.lifecycle_policy_resource_type.LifecyclePolicyResourceType",
    policy_details: "capo_imagebuilder.types.lifecycle_policy_details.LifecyclePolicyDetails",
    resource_selection: "capo_imagebuilder.types.lifecycle_policy_resource_selection.LifecyclePolicyResourceSelection",
    client_token: "capo_imagebuilder.types.client_token.ClientToken",
    *,
    config_overrides: Optional[imagebuilderClientConfig] = None,
    description: Optional[
        "capo_imagebuilder.types.non_empty_string.NonEmptyString"
    ] = None,
    status: Optional[
        "capo_imagebuilder.types.lifecycle_policy_status.LifecyclePolicyStatus"
    ] = None,
) -> "capo_imagebuilder.types.update_lifecycle_policy_response.UpdateLifecyclePolicyResponse":
    """<p>Updates the specified lifecycle policy. The request replaces the existing policy configuration rather than merging changes, so re-specify every setting that you want to keep. The <code>resourceType</code> must match the existing policy's value.</p>

    Args:
        lifecycle_policy_arn: <p>The Amazon Resource Name (ARN) of the lifecycle policy resource.</p>
        description: <p>Optional description for the lifecycle policy. Because the update replaces the entire configuration, omitting this property removes any existing description.</p>
        status: <p>Indicates whether the lifecycle policy resource is enabled. Defaults to <code>ENABLED</code> when omitted, so updating a disabled policy without setting this property re-enables it.</p>
        execution_role: <p>The name or Amazon Resource Name (ARN) for the IAM role you create that grants Image Builder access to run lifecycle actions.</p>
        resource_type: <p>The type of image resource that the lifecycle policy applies to. The value must match the policy's existing resource type. You can't change the resource type of an existing lifecycle policy.</p>
        policy_details: <p>The configuration details for a lifecycle policy resource.</p>
        resource_selection: <p>Selection criteria for resources that the lifecycle policy applies to. You must specify exactly one selection criteria: either recipes or a tag map, not both.</p>
        client_token: <p>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 <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html">Ensuring idempotency</a> in the <i>Amazon EC2 API Reference</i>.</p>

    Raises:
        capo_imagebuilder.errors.call_rate_limit_exceeded_exception.CallRateLimitExceededException: <p>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.</p>
        capo_imagebuilder.errors.client_exception.ClientException: <p>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.</p>
        capo_imagebuilder.errors.forbidden_exception.ForbiddenException: <p>You are not authorized to perform the requested operation.</p>
        capo_imagebuilder.errors.idempotent_parameter_mismatch_exception.IdempotentParameterMismatchException: <p>You have specified a client token for an operation using parameter values that differ from a previous request that used the same client token.</p>
        capo_imagebuilder.errors.invalid_parameter_combination_exception.InvalidParameterCombinationException: <p>You have specified a combination of parameters that isn't valid. For example, two mutually exclusive parameters, or a parameter without its required companion parameter. Review the error message for details.</p>
        capo_imagebuilder.errors.invalid_request_exception.InvalidRequestException: <p>The request is malformed or otherwise invalid. Verify the request and try again.</p>
        capo_imagebuilder.errors.resource_in_use_exception.ResourceInUseException: <p>The resource that you are trying to operate on is currently in use. Review the message details and retry later.</p>
        capo_imagebuilder.errors.service_exception.ServiceException: <p>An internal server error occurred while Image Builder processed the request. Retrying the request may succeed.</p>
        capo_imagebuilder.errors.service_unavailable_exception.ServiceUnavailableException: <p>The service is unable to process your request at this time.</p>
        capo_imagebuilder.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Update a lifecycle policy
        The following example updates a lifecycle policy to delete AMI images and their associated snapshots after 12 months, retaining the 3 most recent images.

        >>> client.update_lifecycle_policy(lifecycle_policy_arn='arn:aws:imagebuilder:us-west-2:111122223333:lifecycle-policy/my-example-policy', description='Deletes AMI images and their snapshots after 12 months, retaining the 3 most recent', status='ENABLED', execution_role='arn:aws:iam::111122223333:role/my-example-lifecycle-role', resource_type='AMI_IMAGE', policy_details=[{'action': {'type': 'DELETE', 'includeResources': {'amis': True, 'snapshots': True}}, 'filter': {'type': 'AGE', 'value': 12, 'unit': 'MONTHS', 'retainAtLeast': 3}}], resource_selection={'tagMap': {'environment': 'production'}}, client_token='a1b2c3d4-5678-90ab-cdef-EXAMPLEaaaaa')
    """

    def _handler(
        req: "OperationRequest[capo_imagebuilder.types.update_lifecycle_policy_request.UpdateLifecyclePolicyRequest]",
    ) -> OperationResponse[
        "capo_imagebuilder.types.update_lifecycle_policy_response.UpdateLifecyclePolicyResponse"
    ]:
        import capo_imagebuilder._operations.imagebuilder.update_lifecycle_policy

        output, http_response = (
            capo_imagebuilder._operations.imagebuilder.update_lifecycle_policy.update_lifecycle_policy(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("UpdateLifecyclePolicy")
    )
    input_: capo_imagebuilder.types.update_lifecycle_policy_request.UpdateLifecyclePolicyRequest = {
        "lifecycle_policy_arn": lifecycle_policy_arn,
        "execution_role": execution_role,
        "resource_type": resource_type,
        "policy_details": policy_details,
        "resource_selection": resource_selection,
        "client_token": client_token,
    }
    if description is not None:
        input_["description"] = description
    if status is not None:
        input_["status"] = status

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output