DeleteSecurityGroup - Amazon Elastic Compute Cloud
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

DeleteSecurityGroup

Deletes a security group.

If you attempt to delete a security group that is associated with an instance, or is referenced by another security group, the operation fails with InvalidGroup.InUse in EC2-Classic or DependencyViolation in EC2-VPC.

Note

We are retiring EC2-Classic. We recommend that you migrate from EC2-Classic to a VPC. For more information, see Migrate from EC2-Classic to a VPC in the Amazon Elastic Compute Cloud User Guide.

Request Parameters

The following parameters are for this specific action. For more information about required and optional parameters that are common to all actions, see Common Query Parameters.

DryRun

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.

Type: Boolean

Required: No

GroupId

The ID of the security group. Required for a nondefault VPC.

Type: String

Required: No

GroupName

[EC2-Classic, 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.

Type: String

Required: No

Response Elements

The following elements are returned by the service.

requestId

The ID of the request.

Type: String

return

Is true if the request succeeds, and an error otherwise.

Type: Boolean

Errors

For information about the errors that are common to all actions, see Common client error codes.

Examples

Example for EC2-Classic

This example deletes the specified security group for EC2-Classic.

Sample Request

https://ec2.amazonaws.com/?Action=DeleteSecurityGroup &GroupName=websrv &AUTHPARAMS

Sample Response

<DeleteSecurityGroupResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> <return>true</return> </DeleteSecurityGroupResponse>

Example for EC2-VPC

his example deletes the specified security group for EC2-VPC.

Sample Request

https://ec2.amazonaws.com/?Action=DeleteSecurityGroup &GroupId=sg-1a2b3c4d &AUTHPARAMS

Sample Response

<DeleteSecurityGroupResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> <return>true</return> </DeleteSecurityGroupResponse>

See Also

For more information about using this API in one of the language-specific Amazon SDKs, see the following: