Connections Class
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
ts
// 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],
});
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_ec2 as ec2
# peer: ec2.IPeer
# port: ec2.Port
# security_group: ec2.SecurityGroup
connections = ec2.Connections(
default_port=port,
peer=peer,
security_groups=[security_group]
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.ec2.*;
IPeer peer;
Port port;
SecurityGroup securityGroup;
Connections connections = Connections.Builder.create()
.defaultPort(port)
.peer(peer)
.securityGroups(List.of(securityGroup))
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.EC2;
IPeer peer;
Port port;
SecurityGroup securityGroup;
var connections = new Connections(new ConnectionsProps {
DefaultPort = port,
Peer = peer,
SecurityGroups = new [] { securityGroup }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
var peer IPeer
var port Port
var securityGroup SecurityGroup
connections := awscdk.Aws_ec2.NewConnections(&ConnectionsProps{
DefaultPort: port,
Peer: peer,
SecurityGroups: []ISecurityGroup{
securityGroup,
},
})
Initializer
ts
new Connections(props?: ConnectionsProps)
python
Connections(props: typing.Optional[ConnectionsProps] = None)
java
new Connections(ConnectionsProps props)
csharp
new Connections(ConnectionsProps? props = null)
go
NewConnections(Props ConnectionsProps)
Properties
connectionsConnectionsconnectionsConnectionsconnectionsConnectionsConnectionsConnectionsConnectionsConnectionsrequired#The network connections associated with this resource.
The default port configured for this connection peer, if available.
securityGroupsISecurityGroup[]security_groupstyping.List[ISecurityGroup]securityGroupsList<ISecurityGroup>SecurityGroupsISecurityGroup[]SecurityGroups*[]ISecurityGrouprequired#Methods
addSecurityGroup(...securityGroups: ISecurityGroup[]): voiddef add_security_group(self, security_groups: ISecurityGroup) -> Nonepublic void addSecurityGroup(ISecurityGroup securityGroups)public void AddSecurityGroup(ISecurityGroup securityGroups)func AddSecurityGroup(SecurityGroups ISecurityGroup)#Add a security group to the list of security groups managed by this object.
allowDefaultPortFrom(other: IConnectable, description?: string): voiddef allow_default_port_from(self, other: IConnectable, description: typing.Optional[str] = None) -> Nonepublic void allowDefaultPortFrom(IConnectable other, String description)public void AllowDefaultPortFrom(IConnectable other, string? description = null)func AllowDefaultPortFrom(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?: string): voiddef allow_default_port_from_any_ipv4(self, description: typing.Optional[str] = None) -> Nonepublic void allowDefaultPortFromAnyIpv4(String description)public void AllowDefaultPortFromAnyIpv4(string? description = null)func AllowDefaultPortFromAnyIpv4(Description *string)#Allow default connections from all IPv4 ranges.
allowDefaultPortInternally(description?: string): voiddef allow_default_port_internally(self, description: typing.Optional[str] = None) -> Nonepublic void allowDefaultPortInternally(String description)public void AllowDefaultPortInternally(string? description = null)func AllowDefaultPortInternally(Description *string)#Allow hosts inside the security group to connect to each other.
allowDefaultPortTo(other: IConnectable, description?: string): voiddef allow_default_port_to(self, other: IConnectable, description: typing.Optional[str] = None) -> Nonepublic void allowDefaultPortTo(IConnectable other, String description)public void AllowDefaultPortTo(IConnectable other, string? description = null)func AllowDefaultPortTo(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: IConnectable, portRange: Port, description?: string): voiddef allow_from(self, other: IConnectable, port_range: Port, description: typing.Optional[str] = None) -> Nonepublic void allowFrom(IConnectable other, Port portRange, String description)public void AllowFrom(IConnectable other, Port portRange, string? description = null)func AllowFrom(Other IConnectable, PortRange Port, Description *string)#Allow connections from the peer on the given port.
allowFromAnyIpv4(portRange: Port, description?: string): voiddef allow_from_any_ipv4(self, port_range: Port, description: typing.Optional[str] = None) -> Nonepublic void allowFromAnyIpv4(Port portRange, String description)public void AllowFromAnyIpv4(Port portRange, string? description = null)func AllowFromAnyIpv4(PortRange Port, Description *string)#Allow from any IPv4 ranges.
allowInternally(portRange: Port, description?: string): voiddef allow_internally(self, port_range: Port, description: typing.Optional[str] = None) -> Nonepublic void allowInternally(Port portRange, String description)public void AllowInternally(Port portRange, string? description = null)func AllowInternally(PortRange Port, Description *string)#Allow hosts inside the security group to connect to each other on the given port.
allowTo(other: IConnectable, portRange: Port, description?: string): voiddef allow_to(self, other: IConnectable, port_range: Port, description: typing.Optional[str] = None) -> Nonepublic void allowTo(IConnectable other, Port portRange, String description)public void AllowTo(IConnectable other, Port portRange, string? description = null)func AllowTo(Other IConnectable, PortRange Port, Description *string)#Allow connections to the peer on the given port.
allowToAnyIpv4(portRange: Port, description?: string): voiddef allow_to_any_ipv4(self, port_range: Port, description: typing.Optional[str] = None) -> Nonepublic void allowToAnyIpv4(Port portRange, String description)public void AllowToAnyIpv4(Port portRange, string? description = null)func AllowToAnyIpv4(PortRange Port, Description *string)#Allow to all IPv4 ranges.
allowToDefaultPort(other: IConnectable, description?: string): voiddef allow_to_default_port(self, other: IConnectable, description: typing.Optional[str] = None) -> Nonepublic void allowToDefaultPort(IConnectable other, String description)public void AllowToDefaultPort(IConnectable other, string? description = null)func AllowToDefaultPort(Other IConnectable, Description *string)#Allow connections to the security group on their default port.