Skip to content

create_rule async

create_rule(
    retention_period: RetentionPeriod,
    resource_type: ResourceType,
    *,
    config_overrides: Optional[AsyncrbinClientConfig] = None,
    description: Optional[Description] = None,
    tags: Optional[TagList] = None,
    resource_tags: Optional[ResourceTags] = None,
    lock_configuration: Optional[LockConfiguration] = None,
    exclude_resource_tags: Optional[ExcludeResourceTags] = None,
) -> CreateRuleResponse

Creates a Recycle Bin retention rule. You can create two types of retention rules:

  • Tag-level retention rules - These retention rules use resource tags to identify the resources to protect. For each retention rule, you specify one or more tag key and value pairs. Resources (of the specified type) that have at least one of these tag key and value pairs are automatically retained in the Recycle Bin upon deletion. Use this type of retention rule to protect specific resources in your account based on their tags.

  • Region-level retention rules - These retention rules, by default, apply to all of the resources (of the specified type) in the Region, even if the resources are not tagged. However, you can specify exclusion tags to exclude resources that have specific tags. Use this type of retention rule to protect all resources of a specific type in a Region.

For more information, see Create Recycle Bin retention rules in the Amazon EBS User Guide.

Parameters:

  • retention_period (RetentionPeriod) –

    Information about the retention period for which the retention rule is to retain resources.

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

    The retention rule description.

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

    Information about the tags to assign to the retention rule.

  • resource_type (ResourceType) –

    The resource type to be retained by the retention rule. Currently, only EBS volumes, EBS snapshots, and EBS-backed AMIs are supported.

    • To retain EBS volumes, specify EBS_VOLUME.

    • To retain EBS snapshots, specify EBS_SNAPSHOT

    • To retain EBS-backed AMIs, specify EC2_IMAGE.

  • resource_tags (Optional[ResourceTags], default: None ) –

    [Tag-level retention rules only] Specifies the resource tags to use to identify resources that are to be retained by a tag-level retention rule. For tag-level retention rules, only deleted resources, of the specified resource type, that have one or more of the specified tag key and value pairs are retained. If a resource is deleted, but it does not have any of the specified tag key and value pairs, it is immediately deleted without being retained by the retention rule.

    You can add the same tag key and value pair to a maximum or five retention rules.

    To create a Region-level retention rule, omit this parameter. A Region-level retention rule does not have any resource tags specified. It retains all deleted resources of the specified resource type in the Region in which the rule is created, even if the resources are not tagged.

  • lock_configuration (Optional[LockConfiguration], default: None ) –

    Information about the retention rule lock configuration.

  • exclude_resource_tags (Optional[ExcludeResourceTags], default: None ) –

    [Region-level retention rules only] Specifies the exclusion tags to use to identify resources that are to be excluded, or ignored, by a Region-level retention rule. Resources that have any of these tags are not retained by the retention rule upon deletion.

    You can't specify exclusion tags for tag-level retention rules.

Raises:

Source code in docs_src/capo_rbin/_services/async_rbin.py
async def create_rule(
    self,
    retention_period: "capo_rbin.types.retention_period.RetentionPeriod",
    resource_type: "capo_rbin.types.resource_type.ResourceType",
    *,
    config_overrides: Optional[AsyncrbinClientConfig] = None,
    description: Optional["capo_rbin.types.description.Description"] = None,
    tags: Optional["capo_rbin.types.tag_list.TagList"] = None,
    resource_tags: Optional["capo_rbin.types.resource_tags.ResourceTags"] = None,
    lock_configuration: Optional[
        "capo_rbin.types.lock_configuration.LockConfiguration"
    ] = None,
    exclude_resource_tags: Optional[
        "capo_rbin.types.exclude_resource_tags.ExcludeResourceTags"
    ] = None,
) -> "capo_rbin.types.create_rule_response.CreateRuleResponse":
    """<p>Creates a Recycle Bin retention rule. You can create two types of retention rules:</p> <ul> <li> <p> <b>Tag-level retention rules</b> - These retention rules use resource tags to identify the resources to protect. For each retention rule, you specify one or more tag key and value pairs. Resources (of the specified type) that have at least one of these tag key and value pairs are automatically retained in the Recycle Bin upon deletion. Use this type of retention rule to protect specific resources in your account based on their tags.</p> </li> <li> <p> <b>Region-level retention rules</b> - These retention rules, by default, apply to all of the resources (of the specified type) in the Region, even if the resources are not tagged. However, you can specify exclusion tags to exclude resources that have specific tags. Use this type of retention rule to protect all resources of a specific type in a Region.</p> </li> </ul> <p>For more information, see <a href="https://docs.aws.amazon.com/ebs/latest/userguide/recycle-bin.html"> Create Recycle Bin retention rules</a> in the <i>Amazon EBS User Guide</i>.</p>

    Args:
        retention_period: <p>Information about the retention period for which the retention rule is to retain resources.</p>
        description: <p>The retention rule description.</p>
        tags: <p>Information about the tags to assign to the retention rule.</p>
        resource_type: <p>The resource type to be retained by the retention rule. Currently, only EBS volumes, EBS snapshots, and EBS-backed AMIs are supported.</p> <ul> <li> <p>To retain EBS volumes, specify <code>EBS_VOLUME</code>.</p> </li> <li> <p>To retain EBS snapshots, specify <code>EBS_SNAPSHOT</code> </p> </li> <li> <p>To retain EBS-backed AMIs, specify <code>EC2_IMAGE</code>.</p> </li> </ul>
        resource_tags: <p>[Tag-level retention rules only] Specifies the resource tags to use to identify resources that are to be retained by a tag-level retention rule. For tag-level retention rules, only deleted resources, of the specified resource type, that have one or more of the specified tag key and value pairs are retained. If a resource is deleted, but it does not have any of the specified tag key and value pairs, it is immediately deleted without being retained by the retention rule.</p> <p>You can add the same tag key and value pair to a maximum or five retention rules.</p> <p>To create a Region-level retention rule, omit this parameter. A Region-level retention rule does not have any resource tags specified. It retains all deleted resources of the specified resource type in the Region in which the rule is created, even if the resources are not tagged.</p>
        lock_configuration: <p>Information about the retention rule lock configuration.</p>
        exclude_resource_tags: <p>[Region-level retention rules only] Specifies the exclusion tags to use to identify resources that are to be excluded, or ignored, by a Region-level retention rule. Resources that have any of these tags are not retained by the retention rule upon deletion.</p> <p>You can't specify exclusion tags for tag-level retention rules.</p>

    Raises:
        capo_rbin.errors.internal_server_exception.InternalServerException: <p>The service could not respond to the request due to an internal problem.</p>
        capo_rbin.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request would cause a service quota for the number of tags per resource to be exceeded.</p>
        capo_rbin.errors.validation_exception.ValidationException: <p>One or more of the parameters in the request is not valid.</p>
        capo_rbin.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_rbin.types.create_rule_request.CreateRuleRequest]",
    ) -> AsyncOperationResponse[
        "capo_rbin.types.create_rule_response.CreateRuleResponse"
    ]:
        import capo_rbin._operations.amazon_recycle_bin.create_rule

        (
            output,
            http_response,
        ) = await capo_rbin._operations.amazon_recycle_bin.create_rule.async_create_rule(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateRule")
    )
    input_: capo_rbin.types.create_rule_request.CreateRuleRequest = {
        "retention_period": retention_period,
        "resource_type": resource_type,
    }
    if description is not None:
        input_["description"] = description
    if tags is not None:
        input_["tags"] = tags
    if resource_tags is not None:
        input_["resource_tags"] = resource_tags
    if lock_configuration is not None:
        input_["lock_configuration"] = lock_configuration
    if exclude_resource_tags is not None:
        input_["exclude_resource_tags"] = exclude_resource_tags

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