aws-cdk-lib.aws_ec2.VpnConnection

class VpnConnection (construct)

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

Implements IConstruct, IDependable, IResource, IVpnConnection

Define a VPN Connection.

Example

// Across all tunnels in the account/region
const allDataOut = ec2.VpnConnection.metricAllTunnelDataOut();

// For a specific vpn connection
const vpnConnection = vpc.addVpnConnection('Dynamic', {
  ip: '1.2.3.4'
});
const state = vpnConnection.metricTunnelState();

Initializer

new VpnConnection(scope: Construct, id: string, props: VpnConnectionProps)

Parameters

  • scope Construct
  • id string
  • props VpnConnectionProps

Construct Props

NameTypeDescription
ipstringThe ip address of the customer gateway.
vpcIVpcThe VPC to connect to.
asn?numberThe ASN of the customer gateway.
staticRoutes?string[]The static routes to be routed from the VPN gateway to the customer gateway.
tunnelOptions?VpnTunnelOption[]The tunnel options for the VPN connection.

ip

Type: string

The ip address of the customer gateway.


vpc

Type: IVpc

The VPC to connect to.


asn?

Type: number (optional, default: 65000)

The ASN of the customer gateway.


staticRoutes?

Type: string[] (optional, default: Dynamic routing (BGP))

The static routes to be routed from the VPN gateway to the customer gateway.


tunnelOptions?

Type: VpnTunnelOption[] (optional, default: Amazon generated tunnel options)

The tunnel options for the VPN connection.

At most two elements (one per tunnel). Duplicates not allowed.

Properties

NameTypeDescription
customerGatewayAsnnumberThe ASN of the customer gateway.
customerGatewayIdstringThe id of the customer gateway.
customerGatewayIpstringThe ip address of the customer gateway.
envResourceEnvironmentThe environment this resource belongs to.
nodeNodeThe tree node.
stackStackThe stack in which this resource is defined.
vpnIdstringThe id of the VPN connection.

customerGatewayAsn

Type: number

The ASN of the customer gateway.


customerGatewayId

Type: string

The id of the customer gateway.


customerGatewayIp

Type: string

The ip address of the customer gateway.


env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


node

Type: Node

The tree node.


stack

Type: Stack

The stack in which this resource is defined.


vpnId

Type: string

The id of the VPN connection.

Methods

NameDescription
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
metric(metricName, props?)Return the given named metric for this VPNConnection.
metricTunnelDataIn(props?)The bytes received through the VPN tunnel.
metricTunnelDataOut(props?)The bytes sent through the VPN tunnel.
metricTunnelState(props?)The state of the tunnel. 0 indicates DOWN and 1 indicates UP.
toString()Returns a string representation of this construct.
static fromVpnConnectionAttributes(scope, id, attrs)Import a VPN connection by supplying all attributes directly.
static metricAll(metricName, props?)Return the given named metric for all VPN connections in the account/region.
static metricAllTunnelDataIn(props?)Metric for the tunnel data in of all VPN connections in the account/region.
static metricAllTunnelDataOut(props?)Metric for the tunnel data out of all VPN connections.
static metricAllTunnelState(props?)Metric for the tunnel state of all VPN connections in the account/region.

applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


metric(metricName, props?)

public metric(metricName: string, props?: MetricOptions): Metric

Parameters

  • metricName string
  • props MetricOptions

Returns

  • Metric

Return the given named metric for this VPNConnection.


metricTunnelDataIn(props?)

public metricTunnelDataIn(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

The bytes received through the VPN tunnel.

Sum over 5 minutes


metricTunnelDataOut(props?)

public metricTunnelDataOut(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

The bytes sent through the VPN tunnel.

Sum over 5 minutes


metricTunnelState(props?)

public metricTunnelState(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

The state of the tunnel. 0 indicates DOWN and 1 indicates UP.

Average over 5 minutes


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromVpnConnectionAttributes(scope, id, attrs)

public static fromVpnConnectionAttributes(scope: Construct, id: string, attrs: VpnConnectionAttributes): IVpnConnection

Parameters

  • scope Construct
  • id string
  • attrs VpnConnectionAttributes

Returns

  • IVpnConnection

Import a VPN connection by supplying all attributes directly.


static metricAll(metricName, props?)

public static metricAll(metricName: string, props?: MetricOptions): Metric

Parameters

  • metricName string
  • props MetricOptions

Returns

  • Metric

Return the given named metric for all VPN connections in the account/region.


static metricAllTunnelDataIn(props?)

public static metricAllTunnelDataIn(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Metric for the tunnel data in of all VPN connections in the account/region.


static metricAllTunnelDataOut(props?)

public static metricAllTunnelDataOut(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Metric for the tunnel data out of all VPN connections.


static metricAllTunnelState(props?)

public static metricAllTunnelState(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Metric for the tunnel state of all VPN connections in the account/region.