Skip to content

EC2  >  Operations  >  create_security_group

create_security_group

Operation

create_security_group async

create_security_group(input: CreateSecurityGroupInput, plugins: list[Plugin] | None = None) -> CreateSecurityGroupOutput

Creates a security group.

A security group acts as a virtual firewall for your instance to control inbound and outbound traffic. For more information, see Amazon EC2 security groups in the Amazon EC2 User Guide and Security groups for your VPC in the Amazon VPC User Guide.

When you create a security group, you specify a friendly name of your choice. You can't have two security groups for the same VPC with the same name.

You have a default security group for use in your VPC. If you don't specify a security group when you launch an instance, the instance is launched into the appropriate default security group. A default security group includes a default rule that grants instances unrestricted network access to each other.

You can add or remove rules from your security groups using AuthorizeSecurityGroupIngress, AuthorizeSecurityGroupEgress, RevokeSecurityGroupIngress, and RevokeSecurityGroupEgress.

For more information about VPC security group limits, see Amazon VPC Limits.

Parameters:

Name Type Description Default
input CreateSecurityGroupInput

An instance of CreateSecurityGroupInput.

required
plugins list[Plugin] | None

A list of callables that modify the configuration dynamically. Changes made by these plugins only apply for the duration of the operation execution and will not affect any other operation invocations.

None

Returns:

Type Description
CreateSecurityGroupOutput

An instance of CreateSecurityGroupOutput.

Input

CreateSecurityGroupInput dataclass

Bases: _SerdeShape

Dataclass for CreateSecurityGroupInput structure.

Attributes

description class-attribute instance-attribute
description: str | None = ...

A description for the security group.

Constraints: Up to 255 characters in length

Valid characters: a-z, A-Z, 0-9, spaces, and ._-:/()#,@[]+=&;{}!$*

dry_run class-attribute instance-attribute
dry_run: bool | 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.

group_name class-attribute instance-attribute
group_name: str | None = ...

The name of the security group. Names are case-insensitive and must be unique within the VPC.

Constraints: Up to 255 characters in length. Can't start with sg-.

Valid characters: a-z, A-Z, 0-9, spaces, and ._-:/()#,@[]+=&;{}!$*

tag_specifications class-attribute instance-attribute
tag_specifications: list[TagSpecification] | None = ...

The tags to assign to the security group.

vpc_id class-attribute instance-attribute
vpc_id: str | None = ...

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

Output

CreateSecurityGroupOutput dataclass

Bases: _SerdeShape

Dataclass for CreateSecurityGroupOutput structure.

Attributes

group_id class-attribute instance-attribute
group_id: str | None = ...

The ID of the security group.

response_metadata class-attribute instance-attribute
response_metadata: ResponseMetadata = ...

Metadata about the response that produced this output. Use this to recover the request identifiers a service's support team needs in order to investigate a call. Members of the metadata are individually optional.

security_group_arn class-attribute instance-attribute
security_group_arn: str | None = ...

The security group ARN.

tags class-attribute instance-attribute
tags: list[Tag] | None = ...

The tags assigned to the security group.