Skip to content

create_lifecycle_policy async

create_lifecycle_policy(
    *,
    config_overrides: Optional[AsyncDLMClientConfig] = None,
    execution_role_arn: Optional[ExecutionRoleArn] = None,
    description: Optional[PolicyDescription] = None,
    state: Optional[SettablePolicyStateValues] = None,
    policy_details: Optional[PolicyDetails] = None,
    tags: Optional[TagMap] = None,
    default_policy: Optional[DefaultPolicyTypeValues] = None,
    create_interval: Optional[CreateInterval] = None,
    retain_interval: Optional[RetainInterval] = None,
    copy_tags: Optional[CopyTagsNullable] = None,
    extend_deletion: Optional[ExtendDeletion] = None,
    cross_region_copy_targets: Optional[CrossRegionCopyTargetList] = None,
    exclusions: Optional[Exclusions] = None,
) -> CreateLifecyclePolicyResponse

Creates an Amazon Data Lifecycle Manager lifecycle policy. Amazon Data Lifecycle Manager supports the following policy types:

  • Custom EBS snapshot policy

  • Custom EBS-backed AMI policy

  • Cross-account copy event policy

  • Default policy for EBS snapshots

  • Default policy for EBS-backed AMIs

For more information, see Default policies vs custom policies.

If you create a default policy, you can specify the request parameters either in the request body, or in the PolicyDetails request structure, but not both.

Parameters:

  • execution_role_arn (Optional[ExecutionRoleArn], default: None ) –

    The Amazon Resource Name (ARN) of the IAM role used to run the operations specified by the lifecycle policy.

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

    A description of the lifecycle policy. The characters ^[0-9A-Za-z _-]+$ are supported.

  • state (Optional[SettablePolicyStateValues], default: None ) –

    The activation state of the lifecycle policy after creation.

  • policy_details (Optional[PolicyDetails], default: None ) –

    The configuration details of the lifecycle policy.

    If you create a default policy, you can specify the request parameters either in the request body, or in the PolicyDetails request structure, but not both.

  • tags (Optional[TagMap], default: None ) –

    The tags to apply to the lifecycle policy during creation.

  • default_policy (Optional[DefaultPolicyTypeValues], default: None ) –

    [Default policies only] Specify the type of default policy to create.

    • To create a default policy for EBS snapshots, that creates snapshots of all volumes in the Region that do not have recent backups, specify VOLUME.

    • To create a default policy for EBS-backed AMIs, that creates EBS-backed AMIs from all instances in the Region that do not have recent backups, specify INSTANCE.

  • create_interval (Optional[CreateInterval], default: None ) –

    [Default policies only] Specifies how often the policy should run and create snapshots or AMIs. The creation frequency can range from 1 to 7 days. If you do not specify a value, the default is 1.

    Default: 1

  • retain_interval (Optional[RetainInterval], default: None ) –

    [Default policies only] Specifies how long the policy should retain snapshots or AMIs before deleting them. The retention period can range from 2 to 14 days, but it must be greater than the creation frequency to ensure that the policy retains at least 1 snapshot or AMI at any given time. If you do not specify a value, the default is 7.

    Default: 7

  • copy_tags (Optional[CopyTagsNullable], default: None ) –

    [Default policies only] Indicates whether the policy should copy tags from the source resource to the snapshot or AMI. If you do not specify a value, the default is false.

    Default: false

  • extend_deletion (Optional[ExtendDeletion], default: None ) –

    [Default policies only] Defines the snapshot or AMI retention behavior for the policy if the source volume or instance is deleted, or if the policy enters the error, disabled, or deleted state.

    By default (ExtendDeletion=false):

    • If a source resource is deleted, Amazon Data Lifecycle Manager will continue to delete previously created snapshots or AMIs, up to but not including the last one, based on the specified retention period. If you want Amazon Data Lifecycle Manager to delete all snapshots or AMIs, including the last one, specify true.

    • If a policy enters the error, disabled, or deleted state, Amazon Data Lifecycle Manager stops deleting snapshots and AMIs. If you want Amazon Data Lifecycle Manager to continue deleting snapshots or AMIs, including the last one, if the policy enters one of these states, specify true.

    If you enable extended deletion (ExtendDeletion=true), you override both default behaviors simultaneously.

    If you do not specify a value, the default is false.

    Default: false

  • cross_region_copy_targets (Optional[CrossRegionCopyTargetList], default: None ) –

    [Default policies only] Specifies destination Regions for snapshot or AMI copies. You can specify up to 3 destination Regions. If you do not want to create cross-Region copies, omit this parameter.

  • exclusions (Optional[Exclusions], default: None ) –

    [Default policies only] Specifies exclusion parameters for volumes or instances for which you do not want to create snapshots or AMIs. The policy will not create snapshots or AMIs for target resources that match any of the specified exclusion parameters.

Raises:

Source code in docs_src/capo_dlm/_services/async_dlm.py
async def create_lifecycle_policy(
    self,
    *,
    config_overrides: Optional[AsyncDLMClientConfig] = None,
    execution_role_arn: Optional[
        "capo_dlm.types.execution_role_arn.ExecutionRoleArn"
    ] = None,
    description: Optional[
        "capo_dlm.types.policy_description.PolicyDescription"
    ] = None,
    state: Optional[
        "capo_dlm.types.settable_policy_state_values.SettablePolicyStateValues"
    ] = None,
    policy_details: Optional["capo_dlm.types.policy_details.PolicyDetails"] = None,
    tags: Optional["capo_dlm.types.tag_map.TagMap"] = None,
    default_policy: Optional[
        "capo_dlm.types.default_policy_type_values.DefaultPolicyTypeValues"
    ] = None,
    create_interval: Optional[
        "capo_dlm.types.create_interval.CreateInterval"
    ] = None,
    retain_interval: Optional[
        "capo_dlm.types.retain_interval.RetainInterval"
    ] = None,
    copy_tags: Optional[
        "capo_dlm.types.copy_tags_nullable.CopyTagsNullable"
    ] = None,
    extend_deletion: Optional[
        "capo_dlm.types.extend_deletion.ExtendDeletion"
    ] = None,
    cross_region_copy_targets: Optional[
        "capo_dlm.types.cross_region_copy_target_list.CrossRegionCopyTargetList"
    ] = None,
    exclusions: Optional["capo_dlm.types.exclusions.Exclusions"] = None,
) -> (
    "capo_dlm.types.create_lifecycle_policy_response.CreateLifecyclePolicyResponse"
):
    """<p>Creates an Amazon Data Lifecycle Manager lifecycle policy. Amazon Data Lifecycle Manager supports the following policy types:</p> <ul> <li> <p>Custom EBS snapshot policy</p> </li> <li> <p>Custom EBS-backed AMI policy</p> </li> <li> <p>Cross-account copy event policy</p> </li> <li> <p>Default policy for EBS snapshots</p> </li> <li> <p>Default policy for EBS-backed AMIs</p> </li> </ul> <p>For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/policy-differences.html"> Default policies vs custom policies</a>.</p> <important> <p>If you create a default policy, you can specify the request parameters either in the request body, or in the PolicyDetails request structure, but not both.</p> </important>

    Args:
        execution_role_arn: <p>The Amazon Resource Name (ARN) of the IAM role used to run the operations specified by the lifecycle policy.</p>
        description: <p>A description of the lifecycle policy. The characters ^[0-9A-Za-z _-]+$ are supported.</p>
        state: <p>The activation state of the lifecycle policy after creation.</p>
        policy_details: <p>The configuration details of the lifecycle policy.</p> <important> <p>If you create a default policy, you can specify the request parameters either in the request body, or in the PolicyDetails request structure, but not both.</p> </important>
        tags: <p>The tags to apply to the lifecycle policy during creation.</p>
        default_policy: <p> <b>[Default policies only]</b> Specify the type of default policy to create.</p> <ul> <li> <p>To create a default policy for EBS snapshots, that creates snapshots of all volumes in the Region that do not have recent backups, specify <code>VOLUME</code>.</p> </li> <li> <p>To create a default policy for EBS-backed AMIs, that creates EBS-backed AMIs from all instances in the Region that do not have recent backups, specify <code>INSTANCE</code>.</p> </li> </ul>
        create_interval: <p> <b>[Default policies only]</b> Specifies how often the policy should run and create snapshots or AMIs. The creation frequency can range from 1 to 7 days. If you do not specify a value, the default is 1.</p> <p>Default: 1</p>
        retain_interval: <p> <b>[Default policies only]</b> Specifies how long the policy should retain snapshots or AMIs before deleting them. The retention period can range from 2 to 14 days, but it must be greater than the creation frequency to ensure that the policy retains at least 1 snapshot or AMI at any given time. If you do not specify a value, the default is 7.</p> <p>Default: 7</p>
        copy_tags: <p> <b>[Default policies only]</b> Indicates whether the policy should copy tags from the source resource to the snapshot or AMI. If you do not specify a value, the default is <code>false</code>.</p> <p>Default: false</p>
        extend_deletion: <p> <b>[Default policies only]</b> Defines the snapshot or AMI retention behavior for the policy if the source volume or instance is deleted, or if the policy enters the error, disabled, or deleted state.</p> <p>By default (<b>ExtendDeletion=false</b>):</p> <ul> <li> <p>If a source resource is deleted, Amazon Data Lifecycle Manager will continue to delete previously created snapshots or AMIs, up to but not including the last one, based on the specified retention period. If you want Amazon Data Lifecycle Manager to delete all snapshots or AMIs, including the last one, specify <code>true</code>.</p> </li> <li> <p>If a policy enters the error, disabled, or deleted state, Amazon Data Lifecycle Manager stops deleting snapshots and AMIs. If you want Amazon Data Lifecycle Manager to continue deleting snapshots or AMIs, including the last one, if the policy enters one of these states, specify <code>true</code>.</p> </li> </ul> <p>If you enable extended deletion (<b>ExtendDeletion=true</b>), you override both default behaviors simultaneously.</p> <p>If you do not specify a value, the default is <code>false</code>.</p> <p>Default: false</p>
        cross_region_copy_targets: <p> <b>[Default policies only]</b> Specifies destination Regions for snapshot or AMI copies. You can specify up to 3 destination Regions. If you do not want to create cross-Region copies, omit this parameter.</p>
        exclusions: <p> <b>[Default policies only]</b> Specifies exclusion parameters for volumes or instances for which you do not want to create snapshots or AMIs. The policy will not create snapshots or AMIs for target resources that match any of the specified exclusion parameters.</p>

    Raises:
        capo_dlm.errors.internal_server_exception.InternalServerException: <p>The service failed in an unexpected way.</p>
        capo_dlm.errors.invalid_request_exception.InvalidRequestException: <p>Bad request. The request is missing required parameters or has invalid parameters.</p>
        capo_dlm.errors.limit_exceeded_exception.LimitExceededException: <p>The request failed because a limit was exceeded.</p>
        capo_dlm.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_dlm.types.create_lifecycle_policy_request.CreateLifecyclePolicyRequest]",
    ) -> AsyncOperationResponse[
        "capo_dlm.types.create_lifecycle_policy_response.CreateLifecyclePolicyResponse"
    ]:
        import capo_dlm._operations.dlm_20180112.create_lifecycle_policy

        (
            output,
            http_response,
        ) = await capo_dlm._operations.dlm_20180112.create_lifecycle_policy.async_create_lifecycle_policy(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateLifecyclePolicy")
    )
    input_: capo_dlm.types.create_lifecycle_policy_request.CreateLifecyclePolicyRequest = {}
    if execution_role_arn is not None:
        input_["execution_role_arn"] = execution_role_arn
    if description is not None:
        input_["description"] = description
    if state is not None:
        input_["state"] = state
    if policy_details is not None:
        input_["policy_details"] = policy_details
    if tags is not None:
        input_["tags"] = tags
    if default_policy is not None:
        input_["default_policy"] = default_policy
    if create_interval is not None:
        input_["create_interval"] = create_interval
    if retain_interval is not None:
        input_["retain_interval"] = retain_interval
    if copy_tags is not None:
        input_["copy_tags"] = copy_tags
    if extend_deletion is not None:
        input_["extend_deletion"] = extend_deletion
    if cross_region_copy_targets is not None:
        input_["cross_region_copy_targets"] = cross_region_copy_targets
    if exclusions is not None:
        input_["exclusions"] = exclusions

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output