aws-cdk-lib.aws_ec2.Peer

class Peer

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

Peer object factories (to be used in Security Group management).

The static methods on this object can be used to create peer objects which represent a connection partner in Security Group rules.

Use this object if you need to represent connection partners using plain IP addresses, or a prefix list ID.

If you want to address a connection partner by Security Group, you can just use the Security Group (or the construct that contains a Security Group) directly, as it already implements IPeer.

Example

declare const instanceType: ec2.InstanceType;

const provider = ec2.NatProvider.instance({
  instanceType,
  defaultAllowedTraffic: ec2.NatTrafficDirection.OUTBOUND_ONLY,
});
new ec2.Vpc(this, 'TheVPC', {
  natGatewayProvider: provider,
});
provider.connections.allowFrom(ec2.Peer.ipv4('1.2.3.4/8'), ec2.Port.tcp(80));

Initializer

new Peer()

Methods

NameDescription
static anyIpv4()Any IPv4 address.
static anyIpv6()Any IPv6 address.
static ipv4(cidrIp)Create an IPv4 peer from a CIDR.
static ipv6(cidrIp)Create an IPv6 peer from a CIDR.
static prefixList(prefixListId)A prefix list.
static securityGroupId(securityGroupId, sourceSecurityGroupOwnerId?)A security group ID.

static anyIpv4()

public static anyIpv4(): IPeer

Returns

  • IPeer

Any IPv4 address.


static anyIpv6()

public static anyIpv6(): IPeer

Returns

  • IPeer

Any IPv6 address.


static ipv4(cidrIp)

public static ipv4(cidrIp: string): IPeer

Parameters

  • cidrIp string

Returns

  • IPeer

Create an IPv4 peer from a CIDR.


static ipv6(cidrIp)

public static ipv6(cidrIp: string): IPeer

Parameters

  • cidrIp string

Returns

  • IPeer

Create an IPv6 peer from a CIDR.


static prefixList(prefixListId)

public static prefixList(prefixListId: string): IPeer

Parameters

  • prefixListId string

Returns

  • IPeer

A prefix list.


static securityGroupId(securityGroupId, sourceSecurityGroupOwnerId?)

public static securityGroupId(securityGroupId: string, sourceSecurityGroupOwnerId?: string): IPeer

Parameters

  • securityGroupId string
  • sourceSecurityGroupOwnerId string

Returns

  • IPeer

A security group ID.