aws-cdk-lib.aws_ec2.Connections

class Connections

LanguageType name
.NETAmazon.CDK.AWS.EC2.Connections
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsec2#Connections
Javasoftware.amazon.awscdk.services.ec2.Connections
Pythonaws_cdk.aws_ec2.Connections
TypeScript (source)aws-cdk-lib » aws_ec2 » Connections

Implements IConnectable

Manage the allowed network connections for constructs with Security Groups.

Security Groups can be thought of as a firewall for network-connected devices. This class makes it easy to allow network connections to and from security groups, and between security groups individually. When establishing connectivity between security groups, it will automatically add rules in both security groups

This object can manage one or more security groups.

Example

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_ec2 as ec2 } from 'aws-cdk-lib';

declare const peer: ec2.IPeer;
declare const port: ec2.Port;
declare const securityGroup: ec2.SecurityGroup;
const connections = new ec2.Connections(/* all optional props */ {
  defaultPort: port,
  peer: peer,
  securityGroups: [securityGroup],
});

Initializer

new Connections(props?: ConnectionsProps)

Parameters

  • props ConnectionsProps

Properties

NameTypeDescription
connectionsConnectionsThe network connections associated with this resource.
securityGroupsISecurityGroup[]
defaultPort?PortThe default port configured for this connection peer, if available.

connections

Type: Connections

The network connections associated with this resource.


securityGroups

Type: ISecurityGroup[]


defaultPort?

Type: Port (optional)

The default port configured for this connection peer, if available.

Methods

NameDescription
addSecurityGroup(...securityGroups)Add a security group to the list of security groups managed by this object.
allowDefaultPortFrom(other, description?)Allow connections from the peer on our default port.
allowDefaultPortFromAnyIpv4(description?)Allow default connections from all IPv4 ranges.
allowDefaultPortInternally(description?)Allow hosts inside the security group to connect to each other.
allowDefaultPortTo(other, description?)Allow connections from the peer on our default port.
allowFrom(other, portRange, description?)Allow connections from the peer on the given port.
allowFromAnyIpv4(portRange, description?)Allow from any IPv4 ranges.
allowInternally(portRange, description?)Allow hosts inside the security group to connect to each other on the given port.
allowTo(other, portRange, description?)Allow connections to the peer on the given port.
allowToAnyIpv4(portRange, description?)Allow to all IPv4 ranges.
allowToDefaultPort(other, description?)Allow connections to the security group on their default port.

addSecurityGroup(...securityGroups)

public addSecurityGroup(...securityGroups: ISecurityGroup[]): void

Parameters

  • securityGroups ISecurityGroup

Add a security group to the list of security groups managed by this object.


allowDefaultPortFrom(other, description?)

public allowDefaultPortFrom(other: IConnectable, description?: string): void

Parameters

  • other IConnectable
  • description string

Allow connections from the peer on our default port.

Even if the peer has a default port, we will always use our default port.


allowDefaultPortFromAnyIpv4(description?)

public allowDefaultPortFromAnyIpv4(description?: string): void

Parameters

  • description string

Allow default connections from all IPv4 ranges.


allowDefaultPortInternally(description?)

public allowDefaultPortInternally(description?: string): void

Parameters

  • description string

Allow hosts inside the security group to connect to each other.


allowDefaultPortTo(other, description?)

public allowDefaultPortTo(other: IConnectable, description?: string): void

Parameters

  • other IConnectable
  • description string

Allow connections from the peer on our default port.

Even if the peer has a default port, we will always use our default port.


allowFrom(other, portRange, description?)

public allowFrom(other: IConnectable, portRange: Port, description?: string): void

Parameters

  • other IConnectable
  • portRange Port
  • description string

Allow connections from the peer on the given port.


allowFromAnyIpv4(portRange, description?)

public allowFromAnyIpv4(portRange: Port, description?: string): void

Parameters

  • portRange Port
  • description string

Allow from any IPv4 ranges.


allowInternally(portRange, description?)

public allowInternally(portRange: Port, description?: string): void

Parameters

  • portRange Port
  • description string

Allow hosts inside the security group to connect to each other on the given port.


allowTo(other, portRange, description?)

public allowTo(other: IConnectable, portRange: Port, description?: string): void

Parameters

  • other IConnectable
  • portRange Port
  • description string

Allow connections to the peer on the given port.


allowToAnyIpv4(portRange, description?)

public allowToAnyIpv4(portRange: Port, description?: string): void

Parameters

  • portRange Port
  • description string

Allow to all IPv4 ranges.


allowToDefaultPort(other, description?)

public allowToDefaultPort(other: IConnectable, description?: string): void

Parameters

  • other IConnectable
  • description string

Allow connections to the security group on their default port.