Skip to main content

cdk-private-api-domain

A reusable AWS CDK construct that provisions a private Amazon API Gateway with a custom domain name, accessible only through VPC endpoints.

This construct simplifies the creation of internal APIs by automatically handling:

  • Private API Gateway with disable_execute_api_endpoint=true.
  • VPC endpoint integration (EndpointType.PRIVATE).
  • Custom domain name setup with ACM certificate.
  • Route 53 record creation in a provided hosted zone.
  • IAM policy enforcement to restrict access to VPC endpoints only.
  • Lambda integration (or any CDK IFunction backend).

🚀 Features

  • Provision internal/private APIs for secure access inside your VPC.
  • Assign a custom subdomain (e.g. api.internal.example.com).
  • Automatically manages Route 53 DNS records and ACM certificates.
  • Attach your Lambda function (or extend to other backends).
  • Reusable in multiple stacks and environments.

📦 Installation

TypeScript / Node.js (npm)

npm install cdk-private-api-domain

Python (PyPI)

pip install cdk-private-api-domain

🛠 Usage

TypeScript

import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as route53 from 'aws-cdk-lib/aws-route53';
import { PrivateApiDomainConstruct } from 'cdk-private-api-domain';

export class MyStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const vpc = ec2.Vpc.fromLookup(this, 'Vpc', { vpcId: 'vpc-1234567890' });
    const fn = new lambda.Function(this, 'MyFunction', {
      runtime: lambda.Runtime.PYTHON_3_11,
      handler: 'index.handler',
      code: lambda.Code.fromAsset('lambda'),
    });
    const hostedZone = route53.HostedZone.fromLookup(this, 'HostedZone', {
      domainName: 'example.com',
    });

    new PrivateApiDomainConstruct(this, 'PrivateApi', {
      vpc,
      handler: fn,
      hostedZone,
      subdomain: 'api',
    });
  }
}

Python

from aws_cdk import (
    App, Stack, aws_ec2 as ec2, aws_lambda as _lambda, aws_route53 as route53
)
from cdk_private_api_domain import PrivateApiDomainConstruct

class MyStack(Stack):
    def __init__(self, scope: App, id: str, **kwargs):
        super().__init__(scope, id, **kwargs)

        vpc = ec2.Vpc.from_lookup(self, "Vpc", vpc_id="vpc-1234567890")

        fn = _lambda.Function(
            self, "MyFunction",
            runtime=_lambda.Runtime.PYTHON_3_11,
            handler="index.handler",
            code=_lambda.Code.from_asset("lambda"),
        )

        hosted_zone = route53.HostedZone.from_lookup(
            self, "HostedZone",
            domain_name="example.com"
        )

        PrivateApiDomainConstruct(
            self, "PrivateApi",
            vpc=vpc,
            handler=fn,
            hosted_zone=hosted_zone,
            subdomain="api"
        )

app = App()
MyStack(app, "MyStack")
app.synth()

🔑 Props

Property Type Description
vpc ec2.IVpc The VPC where the API will be deployed.
handler lambda.IFunction The Lambda function to integrate with API Gateway.
hostedZone route53.IHostedZone The hosted zone where the custom domain record will be created.
subdomain str (Python) / string (TS) The subdomain for the API (e.g. api for api.example.com).

✅ Example Result

  • Creates a private API Gateway endpoint, accessible only via VPC interface endpoints.
  • Deploys with a custom domain (e.g., api.example.com).
  • DNS is automatically set up in Route 53.
  • Secured with an ACM certificate.

📄 License

Distributed under the Apache-2.0 License.

Metadata

Release files for cdk-private-api-domain 0.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cdk-private-api-domain 0.0.0
File Size Uploaded
cdk_private_api_domain-0.0.0.tar.gz 42.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cdk-private-api-domain 0.0.0
File Interpreter ABI Platform
cdk_private_api_domain-0.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 84.1 kB

Release files / cdk_private_api_domain-0.0.0.tar.gz

Download URL cdk_private_api_domain-0.0.0.tar.gz
Size 42.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ca2f9be81e9f7f420e54d13f942c69b69a293ffbde678477195c3c815af46a51
BLAKE2b-256 checksum
How to use checksums
b59bc97abc2d3cb097cafd0a06bfc0271516a905ca623041e8c1c99579a57872
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / cdk_private_api_domain-0.0.0-py3-none-any.whl

Download URL cdk_private_api_domain-0.0.0-py3-none-any.whl
Size 41.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
721e9977aaa1a0152b506e243b7c3ea8ff778182aaaac8f2b4108c9328946f23
BLAKE2b-256 checksum
How to use checksums
1ddd8c25df0edd62281a2aa0ba8c762e097f27223bcb230d16c74d8772556d14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page