Create a security group

Create a named set of firewall rules, add and remove rules, and delete a group no instance uses.

Last updated 18 November 2026View as Markdown

What a group filters is in Networks and addresses. Replace the ids with your own.

Prerequisites

  • Permission for ec2:CreateSecurityGroup. Adding a rule needs ec2:AuthorizeSecurityGroupIngress (inbound) or ec2:AuthorizeSecurityGroupEgress (outbound); removing one ec2:RevokeSecurityGroupIngress or ec2:RevokeSecurityGroupEgress; deleting the group ec2:DeleteSecurityGroup.
  • In the console, also ec2:DescribeSecurityGroups to open Security groups (without it the page says "Access denied") and a group's page (without it the page is not found).
  • Room in the security groups quota.

Create a group

  1. Open Compute, then Security groups, and choose Create security group.
  2. For Name, enter web.
  3. (Optional) For Description, enter a description.
  4. (Optional) Under Rules, choose a Quick add preset (SSH, HTTP, HTTPS, ICMP) or Add rule. For each rule, set Direction, Protocol, Port range, Source (or Destination) and (optional) Note. The console has no default source: a rule needs one, and only the HTTP and HTTPS presets fill in 0.0.0.0/0.
  5. Choose Create. The group appears in the list.

Without inbound rules nothing gets in; outbound traffic is allowed until you add an outbound rule.

You can also create a group from the Security groups picker of the launch form.

Rules

Field Accepted values Default
direction inbound, outbound required
protocol tcp, udp, icmp required
fromPort, toPort 0–65535; ignored for ICMP. Without fromPort: every port; without toPort: fromPort alone none
cidrIpv4 A CIDR block, IPv4 or IPv6, or a single address (stored as /32 or /128) 0.0.0.0/0
description Up to 255 characters none

Another value in cidrIpv4 is refused with 400 "Source must be an IP address (2.31.205.75) or a network in CIDR notation (10.0.0.0/16, 0.0.0.0/0)".

Add or remove a rule

  1. Open the group, then choose Inbound rules or Outbound rules.
  2. Choose Add rule. In Add rule, choose Inbound or Outbound, a Type (a service such as SSH, PostgreSQL or Custom TCP), the ports for a custom type, the Source CIDR (or Destination CIDR, required) and (optional) a Description, then choose Add rule.
  3. To remove a rule, choose Remove rule in its row menu, then Remove.

A rule change is applied to every instance the group is attached to before the call returns. If it cannot be applied, the call answers 502 ("Rule saved but not applied: …" or "Rule removed but the change is not applied: …") and the group shows the error until a change succeeds.

Delete a group

  1. Open the group, then choose Danger zone.
  2. Choose Delete security group, enter the group name, and choose Delete security group.

The group and its rules are removed. The delete is refused with 409 "Security group is attached to … instance(s); detach it first" while an instance that is not terminated has it; the console says so beside Delete security group instead.

Result

A group made here is not bound to a network (vpcId is null): any group can be attached to any instance; see Change an instance's security groups.

A group that a Kubernetes cluster manages cannot be deleted: 409 "This group belongs to Kubernetes cluster …; it goes when the cluster is deleted." Its rules can be changed, except on the cluster's control-plane group, which is refused with 409 (change who may reach the API endpoint in the cluster's networking settings instead).

Did this page help you?