DEV Community
Follow
How to build an API Gateway with a custom domain using AWS CDK
This guide demonstrates creating a custom domain for an AWS API Gateway using the AWS CDK. It emphasizes the importance of branded API endpoints like api.yourcompany.com over default AWS URLs. The process involves provisioning a TLS certificate using AWS Certificate Manager. An API Gateway is then created using the CDK's RestApi construct, specifying the custom domain and certificate. A Route 53 hosted zone is required, and an A record is configured to alias the API Gateway. The CDK code provisions the necessary resources, including the API Gateway, domain name, base path mapping, and Route 53 record. Deployment is done via `cdk diff` and `cdk deploy`. Testing involves using `curl` to access the custom domain. Remember to destroy the stack afterward using `cdk destroy` to avoid costs. The benefits include professional branding, flexible configuration, and built-in SSL/TLS security. This method provides a clean and manageable approach to setting up a custom domain for your API Gateway.