@richkang/cdk-egress-api-proxy
v0.1.1
Published
CDK construct for egress API proxy using a Private AWS API Gateway
Downloads
2
Readme
Egress API Proxy Constructs for AWS CDK
This project contains AWS CDK constructs to set up an API Gateway with a VPC endpoint for secure outbound traffic (egress) management. The main constructs are:
EgressApiProxyConstruct
: Sets up a private API Gateway with a proxy integration to an external API endpoint.EgressApiProxyVpcEndpointConstruct
: Creates a VPC endpoint for the API Gateway to securely manage network traffic.
Getting Started
Prerequisites
- AWS CDK installed
- Node.js installed
- AWS CLI configured
- Basic knowledge of TypeScript and AWS CDK
Installation
Clone this repository:
git clone https://github.com/kangks/cdk-egress-api-proxy.git cd egress-api-proxy-construct
Install dependencies:
npm install
Configuration
Create a
config.json
file in the root of the project with the following structure:{ "dev": { "stack-prefix": "dev", "vpcId": "vpc-123456", "subnets": [ { "avaialbilityZone": "us-east-1a", "subnetId": "subnet-123456" } ], "cidrAPIcallee": "0.0.0.0/0", "rootResource": "api" } }
Adjust the values to match your AWS environment.
Usage
The example provided in
egress-api-proxy.ts
demonstrates how to useEgressApiProxyConstruct
andEgressApiProxyVpcEndpointConstruct
:import 'source-map-support/register'; import * as cdk from 'aws-cdk-lib'; import * as proxy from './egress-api-proxy-construct'; import { EgressApiProxyVpcEndpointConstruct } from './lib/EgressApiProxyVpcEndpointConstruct'; const config = require('./config.json'); const app = new cdk.App(); const stageName = app.node.tryGetContext('stageName'); const prefix = config[stageName]['stack-prefix']; // API Stack const stack = new cdk.Stack(app, `${prefix}-api-stack`); const construct = new proxy.EgressApiProxyConstruct(stack, prefix, { vpcId: config[stageName]['vpcId'], subnets: config[stageName]['subnets'], cidrAPIcallee: config[stageName]['cidrAPIcallee'], rootResource: config[stageName]['rootResource'], }); // VPC Endpoint Stack const vpcStack = new cdk.Stack(app, `${prefix}-vpce-stack`); const vpce = new EgressApiProxyVpcEndpointConstruct(vpcStack, `${prefix}-vpce`, { vpcId: config[stageName]['vpcId'], subnets: config[stageName]['subnets'], CidrAPIcallee: config[stageName]['CidrAPIcallee'], }); vpce.node.addDependency(construct);
Deploy this CDK application to your AWS environment.
npx cdk deploy --context stageName=dev
Clean Up
To delete the created resources, run:
npx cdk destroy --context stageName=dev
License
This project is licensed under the MIT License.