class Peer
| Language | Type name |
|---|---|
.NET | Amazon.CDK.AWS.EC2.Peer |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsec2#Peer |
Java | software.amazon.awscdk.services.ec2.Peer |
Python | aws_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
const natGatewayProvider = ec2.NatProvider.instanceV2({
instanceType: new ec2.InstanceType('t3.small'),
defaultAllowedTraffic: ec2.NatTrafficDirection.NONE,
});
const vpc = new ec2.Vpc(this, 'Vpc', { natGatewayProvider });
const securityGroup = new ec2.SecurityGroup(this, 'SecurityGroup', {
vpc,
allowAllOutbound: false,
});
securityGroup.addEgressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(443));
for (const gatewayInstance of natGatewayProvider.gatewayInstances) {
gatewayInstance.addSecurityGroup(securityGroup);
}
Initializer
new Peer()
Methods
| Name | Description |
|---|---|
| static any | Any IPv4 address. |
| static any | Any IPv6 address. |
| static ipv4(cidrIp) | Create an IPv4 peer from a CIDR. |
| static ipv6(cidrIp) | Create an IPv6 peer from a CIDR. |
| static prefix | A prefix list. |
| static security | A security group ID. |
static anyIpv4()
public static anyIpv4(): IPeer
Returns
Any IPv4 address.
static anyIpv6()
public static anyIpv6(): IPeer
Returns
Any IPv6 address.
static ipv4(cidrIp)
public static ipv4(cidrIp: string): IPeer
Parameters
- cidrIp
string
Returns
Create an IPv4 peer from a CIDR.
static ipv6(cidrIp)
public static ipv6(cidrIp: string): IPeer
Parameters
- cidrIp
string
Returns
Create an IPv6 peer from a CIDR.
static prefixList(prefixListId)
public static prefixList(prefixListId: string): IPeer
Parameters
- prefixListId
string
Returns
A prefix list.
static securityGroupId(securityGroupId, sourceSecurityGroupOwnerId?)
public static securityGroupId(securityGroupId: string, sourceSecurityGroupOwnerId?: string): IPeer
Parameters
- securityGroupId
string - sourceSecurityGroupOwnerId
string
Returns
A security group ID.

.NET
Go
Java
Python
TypeScript (