Skip to content

delete_tags

delete_tags(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    dry_run: Optional[Boolean] = None,
    resources: Optional[ResourceIdList] = None,
    tags: Optional[TagList] = None,
) -> None

Deletes the specified set of tags from the specified set of resources.

To list the current tags, use DescribeTags. For more information about tags, see Tag your Amazon EC2 resources in the Amazon Elastic Compute Cloud User Guide.

Parameters:

  • dry_run (Optional[Boolean], default: None ) –

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • resources (Optional[ResourceIdList], default: None ) –

    The IDs of the resources, separated by spaces.

    Constraints: Up to 1000 resource IDs. We recommend breaking up this request into smaller batches.

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

    The tags to delete. Specify a tag key and an optional tag value to delete specific tags. If you specify a tag key without a tag value, we delete any tag with this key regardless of its value. If you specify a tag key with an empty string as the tag value, we delete the tag only if its value is an empty string.

    If you omit this parameter, we delete all user-defined tags for the specified resources. We do not delete Amazon Web Services-generated tags (tags that have the aws: prefix).

    Constraints: Up to 1000 tags.

Raises:

Examples:

To delete a tag from a resource This example deletes the tag Stack=test from the specified image.

>>> client.delete_tags(resources=['ami-78a54011'], tags=[{'Key': 'Stack', 'Value': 'test'}])
Source code in docs_src/capo_ec2/_services/ec2.py
def delete_tags(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    resources: Optional["capo_ec2.types.resource_id_list.ResourceIdList"] = None,
    tags: Optional["capo_ec2.types.tag_list.TagList"] = None,
) -> None:
    """<p>Deletes the specified set of tags from the specified set of resources.</p> <p>To list the current tags, use <a>DescribeTags</a>. For more information about tags, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html">Tag your Amazon EC2 resources</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>.</p>

    Args:
        dry_run: <p>Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>
        resources: <p>The IDs of the resources, separated by spaces.</p> <p>Constraints: Up to 1000 resource IDs. We recommend breaking up this request into smaller batches.</p>
        tags: <p>The tags to delete. Specify a tag key and an optional tag value to delete specific tags. If you specify a tag key without a tag value, we delete any tag with this key regardless of its value. If you specify a tag key with an empty string as the tag value, we delete the tag only if its value is an empty string.</p> <p>If you omit this parameter, we delete all user-defined tags for the specified resources. We do not delete Amazon Web Services-generated tags (tags that have the <code>aws:</code> prefix).</p> <p>Constraints: Up to 1000 tags.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To delete a tag from a resource
        This example deletes the tag Stack=test from the specified image.

        >>> client.delete_tags(resources=['ami-78a54011'], tags=[{'Key': 'Stack', 'Value': 'test'}])
    """

    def _handler(
        req: "OperationRequest[capo_ec2.types.delete_tags_request.DeleteTagsRequest]",
    ) -> OperationResponse[None]:
        import capo_ec2._operations.amazon_ec2.delete_tags

        output, http_response = (
            capo_ec2._operations.amazon_ec2.delete_tags.delete_tags(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DeleteTags")
    )
    input_: capo_ec2.types.delete_tags_request.DeleteTagsRequest = {}
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if resources is not None:
        input_["resources"] = resources
    if tags is not None:
        input_["tags"] = tags

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