NetworkConnector L2 construct Added in v2.276.0
A Lambda Network Connector: network configuration that Lambda compute attaches to.
The connector owns the network interfaces in the VPC. Compute references a connector rather than carrying subnets and security groups itself, so the interfaces are provisioned when the connector is created, not when each function is.
Every update to the connector produces a new immutable version. A WebFunction pins its revision to one version (latestVersionArn), so when the connector in the same stack is updated, the revision is replaced and moves to the new version as part of that deployment. To hold a WebFunction on a fixed version instead — or to reference a connector from another stack — import the version with fromNetworkConnectorVersionArn.
Example
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,
});
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
)
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();
// 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
});
// 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,
})
Initializer
new NetworkConnector(scope: Construct, id: string, props: NetworkConnectorProps)
NetworkConnector(scope: Construct, id: str, props: NetworkConnectorProps)
new NetworkConnector(Construct scope, String id, NetworkConnectorProps props)
new NetworkConnector(Construct scope, string id, NetworkConnectorProps props)
NewNetworkConnector(Scope Construct, Id *string, Props NetworkConnectorProps)
Construct Props
configurationNetworkConnectorConfigurationconfigurationNetworkConnectorConfigurationconfigurationNetworkConnectorConfigurationConfigurationNetworkConnectorConfigurationConfigurationNetworkConnectorConfigurationrequired#networkConnectorNameoptionalstringnetwork_connector_nameoptionalstrnetworkConnectorNameoptionalStringNetworkConnectorNameoptionalstringNetworkConnectorNameoptional*string#Default: a name is generated by CloudFormation
Changing it replaces the connector.
operatorRoleoptionalIRoleRefoperator_roleoptionalIRoleRefoperatorRoleoptionalIRoleRefOperatorRoleoptionalIRoleRefOperatorRoleoptionalIRoleRef#Default: a role is created with the AWSLambdaNetworkConnectorOperatorPolicy managed policy
notes
The AWSLambdaNetworkConnectorOperatorPolicy managed policy is attached to a provided role defined in this app, as it is to the default one. A role imported by ARN or name cannot be modified from this app, so a warning is emitted instead: make sure it already carries that policy, or equivalent permissions to manage the connector's network interfaces.
Use a role dedicated to this connector. The service assumes it without presenting a source account or ARN, so its trust policy cannot be conditioned, and whatever else uses the role gains the permissions to manage network interfaces in the VPC. A function's execution role, for example, already trusts lambda.amazonaws.com, so passing it here would give that function's code those permissions.
tagsoptional{ [key: string]: string }tagsoptionaltyping.Mapping[str, str]tagsoptionalMap<String, String>TagsoptionalIDictionary<string, string>Tagsoptional*map[string]*string#Default: No tags.
Properties
envResourceEnvironmentenvResourceEnvironmentenvResourceEnvironmentEnvResourceEnvironmentEnvResourceEnvironment#notes
For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.
For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.
latestVersionArnstringlatest_version_arnstrlatestVersionArnStringLatestVersionArnstringLatestVersionArn*string#WebFunction pins a revision to this. For a connector defined in this app the value changes on every update to the connector, which replaces the revision that references it.
networkConnectorArnstringnetwork_connector_arnstrnetworkConnectorArnStringNetworkConnectorArnstringNetworkConnectorArn*string#notes
Identifies the connector as a whole, across its versions: use it in IAM policies and for consumers that resolve the current version at run time. It does not name a version, so WebFunction — which pins a revision to one version — does not accept it.
networkConnectorRefNetworkConnectorReferencenetwork_connector_refNetworkConnectorReferencenetworkConnectorRefNetworkConnectorReferenceNetworkConnectorRefNetworkConnectorReferenceNetworkConnectorRefNetworkConnectorReference#operatorRoleIRoleRefoperator_roleIRoleRefoperatorRoleIRoleRefOperatorRoleIRoleRefOperatorRoleIRoleRef#PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringstatic#resourceCfnNetworkConnectorresourceCfnNetworkConnectorresourceCfnNetworkConnectorResourceCfnNetworkConnectorResourceCfnNetworkConnector#Use for escape hatches.
Methods
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#notes · 1 parameter
When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.
Parameters
strengthstrengthstrengthstrengthStrength— - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#notes
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).
fromNetworkConnectorArn(scope: Construct, id: string, networkConnectorArn: string): INetworkConnector@staticmethod def from_network_connector_arn(scope: Construct, id: str, network_connector_arn: str) -> INetworkConnectorpublic static INetworkConnector fromNetworkConnectorArn(Construct scope, String id, String networkConnectorArn)public static INetworkConnector FromNetworkConnectorArn(Construct scope, string id, string networkConnectorArn)func FromNetworkConnectorArn(Scope Construct, Id *string, NetworkConnectorArn *string) INetworkConnectorstatic#The result names the connector as a whole, not a version, so it can be used in IAM policies but not as a WebFunction's egressNetworkConnector; reading latestVersionArn on it throws. Use fromNetworkConnectorVersionArn for that.
1 parameter
Parameters
networkConnectorArnnetwork_connector_arnnetworkConnectorArnnetworkConnectorArnNetworkConnectorArn— An unqualified ARN,arn:...:network-connector:nc-<id>.
fromNetworkConnectorAttributes(scope: Construct, id: string, attrs: NetworkConnectorAttributes): INetworkConnector@staticmethod def from_network_connector_attributes(scope: Construct, id: str, attrs: NetworkConnectorAttributes) -> INetworkConnectorpublic static INetworkConnector fromNetworkConnectorAttributes(Construct scope, String id, NetworkConnectorAttributes attrs)public static INetworkConnector FromNetworkConnectorAttributes(Construct scope, string id, NetworkConnectorAttributes attrs)func FromNetworkConnectorAttributes(Scope Construct, Id *string, Attrs NetworkConnectorAttributes) INetworkConnectorstatic#fromNetworkConnectorVersionArn(scope: Construct, id: string, networkConnectorVersionArn: string): INetworkConnector@staticmethod def from_network_connector_version_arn(scope: Construct, id: str, network_connector_version_arn: str) -> INetworkConnectorpublic static INetworkConnector fromNetworkConnectorVersionArn(Construct scope, String id, String networkConnectorVersionArn)public static INetworkConnector FromNetworkConnectorVersionArn(Construct scope, string id, string networkConnectorVersionArn)func FromNetworkConnectorVersionArn(Scope Construct, Id *string, NetworkConnectorVersionArn *string) INetworkConnectorstatic#notes · 1 parameter
This is the form a WebFunction can reference. The revision stays on this version until the ARN in your code changes, regardless of updates to the connector.
A literal ARN is checked for a version suffix at synthesis. A deploy-time value — an SSM parameter, an imported value — cannot be inspected until deployment, where an unqualified ARN is rejected by the service when the revision is created.
Do not pass the latestVersionArn of a connector in another stack. It changes on every update to the connector, and CloudFormation does not allow an exported value that another stack imports to change; a WebFunction rejects such an import at synthesis.
Parameters
networkConnectorVersionArnnetwork_connector_version_arnnetworkConnectorVersionArnnetworkConnectorVersionArnNetworkConnectorVersionArn— A qualified ARN,arn:...:network-connector:nc-<id>:<version>.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
isNetworkConnector(x: any): boolean@staticmethod def is_network_connector(x: Any) -> boolpublic static Boolean isNetworkConnector(Object x)public static bool IsNetworkConnector(object x)func IsNetworkConnector(X interface{}) *boolstatic#isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.