# 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`.

- Source: [`aws-ec2/lib/peer.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-ec2/lib/peer.ts#L112)
- Type last changed: v2.9.0 · 26 Jan 2022

## Example

```ts
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

```ts
new Peer()
```

## Methods

- `anyIpv4(): IPeer` (static) — Any IPv4 address.

- `anyIpv6(): IPeer` (static) — Any IPv6 address.

- `ipv4(cidrIp: string): IPeer` (static) — Create an IPv4 peer from a CIDR.

- `ipv6(cidrIp: string): IPeer` (static) — Create an IPv6 peer from a CIDR.

- `prefixList(prefixListId: string): IPeer` (static) — A prefix list.

- `securityGroupId(securityGroupId: string, sourceSecurityGroupOwnerId?: string): IPeer` (static) — A security group ID.
