# ISecurityGroup

Interface for security group-like objects.

Extends: ISecurityGroup
Extends: IResource, IPeer, ISecurityGroupRef
Implemented by: SecurityGroup

- Source: [`aws-ec2/lib/security-group.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-ec2/lib/security-group.ts#L38)
- Type last changed: v2.224.0 · 13 Nov 2025

## Properties

- `allowAllOutbound`: boolean — Whether the SecurityGroup has been configured to allow all outbound traffic.

- `canInlineRule`: boolean — Whether the rule can be inlined into a SecurityGroup or not.

- `connections`: [Connections](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Connections.html) — The network connections associated with this resource.

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `securityGroupId`: string — ID for the current security group.

- `securityGroupRef`: [SecurityGroupReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_ec2.SecurityGroupReference.html) — A reference to a SecurityGroup resource.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this resource is defined.

- `uniqueId`: string — A unique identifier for this connection peer.

## Methods

- `addEgressRule(peer: IPeer, connection: Port, description?: string, remoteRule?: boolean): void` — Add an egress rule for the current security group.

  `remoteRule` controls where the Rule object is created if the peer is also a
  securityGroup and they are in different stack. If false (default) the
  rule object is created under the current SecurityGroup object. If true and the
  peer is also a SecurityGroup, the rule object is created under the remote
  SecurityGroup object.

- `addIngressRule(peer: IPeer, connection: Port, description?: string, remoteRule?: boolean): void` — Add an ingress rule for the current security group.

  `remoteRule` controls where the Rule object is created if the peer is also a
  securityGroup and they are in different stack. If false (default) the
  rule object is created under the current SecurityGroup object. If true and the
  peer is also a SecurityGroup, the rule object is created under the remote
  SecurityGroup object.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `toEgressRuleConfig(): EgressRuleConfig` — Produce the egress rule JSON for the given connection.

- `toIngressRuleConfig(): IngressRuleConfig` — Produce the ingress rule JSON for the given connection.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
