# VpcEgressConfiguration

Configuration for a connector that gives the compute egress into a VPC.

- Source: [`aws-lambda/lib/network-connector.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-lambda/lib/network-connector.ts#L70)
- Type last changed: v2.276.0 · 10 Nov 2026

## Example

TypeScript:

```ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';

declare const vpc: ec2.Vpc;
declare const code: lambda.WebFunctionCode;

const securityGroup = new ec2.SecurityGroup(this, 'EgressSecurityGroup', { vpc });

const connector = new lambda.NetworkConnector(this, 'Egress', {
  configuration: lambda.NetworkConnectorConfiguration.vpcEgress({
    computeType: lambda.NetworkConnectorComputeType.WEB_FUNCTION,
    vpc,
    vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS },
    securityGroups: [securityGroup],
  }),
});

new lambda.WebFunction(this, 'MyWebFunction', {
  code,
  runtime: lambda.WebFunctionRuntime.NODEJS_24_X,
  defaultEndpointAuth: lambda.WebFunctionAuthType.IAM_AUTH,
  egressNetworkConnector: connector,
});
```

Python:

```python
import aws_cdk.aws_ec2 as ec2

# vpc: ec2.Vpc
# code: lambda.WebFunctionCode

security_group = ec2.SecurityGroup(self, "EgressSecurityGroup", vpc=vpc)

connector = lambda_.NetworkConnector(self, "Egress",
    configuration=lambda_.NetworkConnectorConfiguration.vpc_egress(
        compute_type=lambda_.NetworkConnectorComputeType.WEB_FUNCTION,
        vpc=vpc,
        vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS),
        security_groups=[security_group]
    )
)

lambda_.WebFunction(self, "MyWebFunction",
    code=code,
    runtime=lambda_.WebFunctionRuntime.NODEJS_24_X,
    default_endpoint_auth=lambda_.WebFunctionAuthType.IAM_AUTH,
    egress_network_connector=connector
)
```

Java:

```java
import software.amazon.awscdk.services.ec2.*;

Vpc vpc;
WebFunctionCode code;

SecurityGroup securityGroup = SecurityGroup.Builder.create(this, "EgressSecurityGroup").vpc(vpc).build();

NetworkConnector connector = NetworkConnector.Builder.create(this, "Egress")
        .configuration(NetworkConnectorConfiguration.vpcEgress(VpcEgressConfiguration.builder()
                .computeType(NetworkConnectorComputeType.WEB_FUNCTION)
                .vpc(vpc)
                .vpcSubnets(SubnetSelection.builder().subnetType(SubnetType.PRIVATE_WITH_EGRESS).build())
                .securityGroups(List.of(securityGroup))
                .build()))
        .build();

WebFunction.Builder.create(this, "MyWebFunction")
        .code(code)
        .runtime(WebFunctionRuntime.NODEJS_24_X)
        .defaultEndpointAuth(WebFunctionAuthType.IAM_AUTH)
        .egressNetworkConnector(connector)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.EC2;

Vpc vpc;
WebFunctionCode code;

var securityGroup = new SecurityGroup(this, "EgressSecurityGroup", new SecurityGroupProps { Vpc = vpc });

var connector = new NetworkConnector(this, "Egress", new NetworkConnectorProps {
    Configuration = NetworkConnectorConfiguration.VpcEgress(new VpcEgressConfiguration {
        ComputeType = NetworkConnectorComputeType.WEB_FUNCTION,
        Vpc = vpc,
        VpcSubnets = new SubnetSelection { SubnetType = SubnetType.PRIVATE_WITH_EGRESS },
        SecurityGroups = new [] { securityGroup }
    })
});

new WebFunction(this, "MyWebFunction", new WebFunctionProps {
    Code = code,
    Runtime = WebFunctionRuntime.NODEJS_24_X,
    DefaultEndpointAuth = WebFunctionAuthType.IAM_AUTH,
    EgressNetworkConnector = connector
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"

var vpc Vpc
var code WebFunctionCode

securityGroup := ec2.NewSecurityGroup(this, jsii.String("EgressSecurityGroup"), &SecurityGroupProps{
	Vpc: Vpc,
})

connector := lambda.NewNetworkConnector(this, jsii.String("Egress"), &NetworkConnectorProps{
	Configuration: lambda.NetworkConnectorConfiguration_VpcEgress(&VpcEgressConfiguration{
		ComputeType: lambda.NetworkConnectorComputeType_WEB_FUNCTION,
		Vpc: *Vpc,
		VpcSubnets: &SubnetSelection{
			SubnetType: ec2.SubnetType_PRIVATE_WITH_EGRESS,
		},
		SecurityGroups: []ISecurityGroupRef{
			securityGroup,
		},
	}),
})

lambda.NewWebFunction(this, jsii.String("MyWebFunction"), &WebFunctionProps{
	Code: Code,
	Runtime: lambda.WebFunctionRuntime_NODEJS_24_X(),
	DefaultEndpointAuth: lambda.WebFunctionAuthType_IAM_AUTH,
	EgressNetworkConnector: connector,
})
```

## Properties

- `computeType`: [NetworkConnectorComputeType](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.NetworkConnectorComputeType.html) (required) — The Lambda compute resource type this connector serves.

  The compute type cannot be changed after the connector is created.

- `networkProtocol`: [NetworkConnectorProtocol](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.NetworkConnectorProtocol.html) = NetworkConnectorProtocol.IPV4 — The IP protocol the network interfaces use.

  The protocol cannot be changed after the connector is created.

- `securityGroups`: [ISecurityGroupRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_ec2.ISecurityGroupRef.html)[] (required) — The security groups to attach to the network interfaces.

  Between 1 and 5 security groups, in the same VPC as the subnets. At least one is required,
  so the interfaces never fall back to the VPC's default security group. The connector only
  initiates connections, so inbound rules are irrelevant; the outbound rules decide what the
  compute can reach.

- `vpc`: [IVpc](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) (required) — The VPC to create network interfaces in.

- `vpcSubnets`: [SubnetSelection](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.SubnetSelection.html) — Which subnets of the VPC to create network interfaces in.

  **Default:** the VPC's default selection: its private subnets, if it has any

  The selection must yield between 1 and 16 subnets.
