Skip to content

delete_security_group async

delete_security_group(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    group_id: Optional[SecurityGroupId] = None,
    group_name: Optional[SecurityGroupName] = None,
    dry_run: Optional[Boolean] = None,
) -> DeleteSecurityGroupResult

Deletes a security group.

If you attempt to delete a security group that is associated with an instance or network interface, is referenced by another security group in the same VPC, or has a VPC association, the operation fails with DependencyViolation.

Parameters:

  • group_id (Optional[SecurityGroupId], default: None ) –

    The ID of the security group.

  • group_name (Optional[SecurityGroupName], default: None ) –

    [Default VPC] The name of the security group. You can specify either the security group name or the security group ID. For security groups in a nondefault VPC, you must specify the security group ID.

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

Raises:

Examples:

To delete a security group This example deletes the specified security group.

>>> await client.delete_security_group(group_id='sg-903004f8')
Source code in docs_src/capo_ec2/_services/async_ec2.py
async def delete_security_group(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    group_id: Optional["capo_ec2.types.security_group_id.SecurityGroupId"] = None,
    group_name: Optional[
        "capo_ec2.types.security_group_name.SecurityGroupName"
    ] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> "capo_ec2.types.delete_security_group_result.DeleteSecurityGroupResult":
    """<p>Deletes a security group.</p> <p>If you attempt to delete a security group that is associated with an instance or network interface, is referenced by another security group in the same VPC, or has a VPC association, the operation fails with <code>DependencyViolation</code>.</p>

    Args:
        group_id: <p>The ID of the security group.</p>
        group_name: <p>[Default VPC] The name of the security group. You can specify either the security group name or the security group ID. For security groups in a nondefault VPC, you must specify the security group ID.</p>
        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>

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

    Examples:
        To delete a security group
        This example deletes the specified security group.

        >>> await client.delete_security_group(group_id='sg-903004f8')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.delete_security_group_request.DeleteSecurityGroupRequest]",
    ) -> AsyncOperationResponse[
        "capo_ec2.types.delete_security_group_result.DeleteSecurityGroupResult"
    ]:
        import capo_ec2._operations.amazon_ec2.delete_security_group

        (
            output,
            http_response,
        ) = await capo_ec2._operations.amazon_ec2.delete_security_group.async_delete_security_group(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DeleteSecurityGroup")
    )
    input_: capo_ec2.types.delete_security_group_request.DeleteSecurityGroupRequest = {}
    if group_id is not None:
        input_["group_id"] = group_id
    if group_name is not None:
        input_["group_name"] = group_name
    if dry_run is not None:
        input_["dry_run"] = dry_run

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