Skip to content
v2.275.0

GatewayVpcEndpoint L2 construct ​

A gateway VPC endpoint.

Example ​

ts
    // Add gateway endpoints when creating the VPC
    const vpc = new ec2.Vpc(this, 'MyVpc', {
      gatewayEndpoints: {
        S3: {
          service: ec2.GatewayVpcEndpointAwsService.S3,
        },
      },
    });

    // Alternatively gateway endpoints can be added on the VPC
    const dynamoDbEndpoint = vpc.addGatewayEndpoint('DynamoDbEndpoint', {
      service: ec2.GatewayVpcEndpointAwsService.DYNAMODB,
    });

    // This allows to customize the endpoint policy
    dynamoDbEndpoint.addToPolicy(
      new iam.PolicyStatement({ // Restrict to listing and describing tables
        principals: [new iam.AnyPrincipal()],
        actions: ['dynamodb:DescribeTable', 'dynamodb:ListTables'],
        resources: ['*'],
      }));

    // Add an interface endpoint
    vpc.addInterfaceEndpoint('EcrDockerEndpoint', {
      service: ec2.InterfaceVpcEndpointAwsService.ECR_DOCKER,

      // Uncomment the following to allow more fine-grained control over
      // who can access the endpoint via the '.connections' object.
      // open: false
    });
python
# Add gateway endpoints when creating the VPC
vpc = ec2.Vpc(self, "MyVpc",
    gateway_endpoints={
        "S3": cdk.aws_ec2.GatewayVpcEndpointOptions(
            service=ec2.GatewayVpcEndpointAwsService.S3
        )
    }
)

# Alternatively gateway endpoints can be added on the VPC
dynamo_db_endpoint = vpc.add_gateway_endpoint("DynamoDbEndpoint",
    service=ec2.GatewayVpcEndpointAwsService.DYNAMODB
)

# This allows to customize the endpoint policy
dynamo_db_endpoint.add_to_policy(
    iam.PolicyStatement( # Restrict to listing and describing tables
        principals=[iam.AnyPrincipal()],
        actions=["dynamodb:DescribeTable", "dynamodb:ListTables"],
        resources=["*"]))

# Add an interface endpoint
vpc.add_interface_endpoint("EcrDockerEndpoint",
    service=ec2.InterfaceVpcEndpointAwsService.ECR_DOCKER
)
java
// Add gateway endpoints when creating the VPC
Vpc vpc = Vpc.Builder.create(this, "MyVpc")
        .gatewayEndpoints(Map.of(
                "S3", GatewayVpcEndpointOptions.builder()
                        .service(GatewayVpcEndpointAwsService.S3)
                        .build()))
        .build();

// Alternatively gateway endpoints can be added on the VPC
GatewayVpcEndpoint dynamoDbEndpoint = vpc.addGatewayEndpoint("DynamoDbEndpoint", GatewayVpcEndpointOptions.builder()
        .service(GatewayVpcEndpointAwsService.DYNAMODB)
        .build());

// This allows to customize the endpoint policy
dynamoDbEndpoint.addToPolicy(
PolicyStatement.Builder.create() // Restrict to listing and describing tables
        .principals(List.of(new AnyPrincipal()))
        .actions(List.of("dynamodb:DescribeTable", "dynamodb:ListTables"))
        .resources(List.of("*")).build());

// Add an interface endpoint
vpc.addInterfaceEndpoint("EcrDockerEndpoint", InterfaceVpcEndpointOptions.builder()
        .service(InterfaceVpcEndpointAwsService.ECR_DOCKER)
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
// Add gateway endpoints when creating the VPC
var vpc = new Vpc(this, "MyVpc", new VpcProps {
    GatewayEndpoints = new Dictionary<string, GatewayVpcEndpointOptions> {
        { "S3", new GatewayVpcEndpointOptions {
            Service = GatewayVpcEndpointAwsService.S3
        } }
    }
});

// Alternatively gateway endpoints can be added on the VPC
var dynamoDbEndpoint = vpc.AddGatewayEndpoint("DynamoDbEndpoint", new GatewayVpcEndpointOptions {
    Service = GatewayVpcEndpointAwsService.DYNAMODB
});

// This allows to customize the endpoint policy
dynamoDbEndpoint.AddToPolicy(
new PolicyStatement(new PolicyStatementProps {  // Restrict to listing and describing tables
    Principals = new [] { new AnyPrincipal() },
    Actions = new [] { "dynamodb:DescribeTable", "dynamodb:ListTables" },
    Resources = new [] { "*" } }));

// Add an interface endpoint
vpc.AddInterfaceEndpoint("EcrDockerEndpoint", new InterfaceVpcEndpointOptions {
    Service = InterfaceVpcEndpointAwsService.ECR_DOCKER
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Add gateway endpoints when creating the VPC
vpc := ec2.NewVpc(this, jsii.String("MyVpc"), &VpcProps{
	GatewayEndpoints: map[string]GatewayVpcEndpointOptions{
		"S3": &GatewayVpcEndpointOptions{
			"service": ec2.GatewayVpcEndpointAwsService_S3(),
		},
	},
})

// Alternatively gateway endpoints can be added on the VPC
dynamoDbEndpoint := vpc.addGatewayEndpoint(jsii.String("DynamoDbEndpoint"), &GatewayVpcEndpointOptions{
	Service: ec2.GatewayVpcEndpointAwsService_DYNAMODB(),
})

// This allows to customize the endpoint policy
dynamoDbEndpoint.AddToPolicy(
iam.NewPolicyStatement(&PolicyStatementProps{
	 // Restrict to listing and describing tables
	Principals: []IPrincipal{
		iam.NewAnyPrincipal(),
	},
	Actions: []*string{
		jsii.String("dynamodb:DescribeTable"),
		jsii.String("dynamodb:ListTables"),
	},
	Resources: []*string{
		jsii.String("*"),
	},
}))

// Add an interface endpoint
vpc.addInterfaceEndpoint(jsii.String("EcrDockerEndpoint"), &InterfaceVpcEndpointOptions{
	Service: ec2.InterfaceVpcEndpointAwsService_ECR_DOCKER(),
})

Initializer ​

ts
new GatewayVpcEndpoint(scope: Construct, id: string, props: GatewayVpcEndpointProps)
python
GatewayVpcEndpoint(scope: Construct, id: str, props: GatewayVpcEndpointProps)
java
new GatewayVpcEndpoint(Construct scope, String id, GatewayVpcEndpointProps props)
csharp
new GatewayVpcEndpoint(Construct scope, string id, GatewayVpcEndpointProps props)
go
NewGatewayVpcEndpoint(Scope Construct, Id *string, Props GatewayVpcEndpointProps)

Construct Props ​

dnsRecordIpTypeoptionalVpcEndpointDnsRecordIpTypedns_record_ip_typeoptionalVpcEndpointDnsRecordIpTypednsRecordIpTypeoptionalVpcEndpointDnsRecordIpTypeDnsRecordIpTypeoptionalVpcEndpointDnsRecordIpTypeDnsRecordIpTypeoptionalVpcEndpointDnsRecordIpType#
Type of DNS records created for the VPC endpoint.

Default: not specified

ipAddressTypeoptionalVpcEndpointIpAddressTypeip_address_typeoptionalVpcEndpointIpAddressTypeipAddressTypeoptionalVpcEndpointIpAddressTypeIpAddressTypeoptionalVpcEndpointIpAddressTypeIpAddressTypeoptionalVpcEndpointIpAddressType#
The IP address type for the endpoint.

Default: not specified

The service to use for this gateway VPC endpoint.
subnetsoptionalSubnetSelection[]subnetsoptionaltyping.List[SubnetSelection]subnetsoptionalList<SubnetSelection>SubnetsoptionalSubnetSelection[]Subnetsoptional*[]SubnetSelection#
Where to add endpoint routing.

Default: All subnets in the VPC

By default, this endpoint will be routable from all subnets in the VPC. Specify a list of subnet selection objects here to be more specific.

example
ts
declare const vpc: ec2.Vpc;

vpc.addGatewayEndpoint('DynamoDbEndpoint', {
  service: ec2.GatewayVpcEndpointAwsService.DYNAMODB,
  // Add only to ISOLATED subnets
  subnets: [
    { subnetType: ec2.SubnetType.PRIVATE_ISOLATED }
  ]
});
vpcIVpcvpcIVpcvpcIVpcVpcIVpcVpcIVpcrequired#
The VPC network in which the gateway endpoint will be used.

Properties ​

The environment this resource belongs to.
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.

nodeNodenodeNodenodeNodeNodeNodeNodeNode#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringstatic#
Uniquely identifies this class.
stackStackstackStackstackStackStackStackStackStack#
The stack in which this resource is defined.
vpcEndpointCreationTimestampstringvpc_endpoint_creation_timestampstrvpcEndpointCreationTimestampStringVpcEndpointCreationTimestampstringVpcEndpointCreationTimestamp*string#
The date and time the gateway VPC endpoint was created.
vpcEndpointDnsEntriesstring[]vpc_endpoint_dns_entriestyping.List[str]vpcEndpointDnsEntriesList<String>VpcEndpointDnsEntriesstring[]VpcEndpointDnsEntries*[]*string#
vpcEndpointIdstringvpc_endpoint_idstrvpcEndpointIdStringVpcEndpointIdstringVpcEndpointId*string#
The gateway VPC endpoint identifier.
vpcEndpointNetworkInterfaceIdsstring[]vpc_endpoint_network_interface_idstyping.List[str]vpcEndpointNetworkInterfaceIdsList<String>VpcEndpointNetworkInterfaceIdsstring[]VpcEndpointNetworkInterfaceIds*[]*string#
vpcEndpointRefVPCEndpointReferencevpc_endpoint_refVPCEndpointReferencevpcEndpointRefVPCEndpointReferenceVpcEndpointRefVPCEndpointReferenceVpcEndpointRefVPCEndpointReference#
A reference to a VPCEndpoint resource.

Methods ​

addToPolicy(statement: PolicyStatement): voiddef add_to_policy(self, statement: PolicyStatement) -> Nonepublic void addToPolicy(PolicyStatement statement)public void AddToPolicy(PolicyStatement statement)func AddToPolicy(Statement PolicyStatement)#
Adds a statement to the policy document of the VPC endpoint. The statement must have a Principal.

Not all interface VPC endpoints support policy. For more information see https://docs.aws.amazon.com/vpc/latest/userguide/vpce-interface.html

1 parameter

Parameters

  • statementstatementstatementstatementStatement — the IAM statement to add.
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)#
Override the cross-stack reference strength for this resource.
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)#
Apply the given removal policy to this resource.
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).

fromGatewayVpcEndpointId(scope: Construct, id: string, gatewayVpcEndpointId: string): IGatewayVpcEndpoint@staticmethod def from_gateway_vpc_endpoint_id(scope: Construct, id: str, gateway_vpc_endpoint_id: str) -> IGatewayVpcEndpointpublic static IGatewayVpcEndpoint fromGatewayVpcEndpointId(Construct scope, String id, String gatewayVpcEndpointId)public static IGatewayVpcEndpoint FromGatewayVpcEndpointId(Construct scope, string id, string gatewayVpcEndpointId)func FromGatewayVpcEndpointId(Scope Construct, Id *string, GatewayVpcEndpointId *string) IGatewayVpcEndpointstatic#
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#
Checks if `x` is a construct.
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.

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#
Returns true if the construct was created by CDK, and false otherwise.
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#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

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.