This pattern in CDK offers a boilerlate to generate an Amazon API Gateway HTTP API endpoint with "ANY" method from the specified path. The Lambda function provided in TypeScript only returns a dummy "HelloWorld".
Amazon API Gateway has two ReSTful API products: REST APIs and HTTP APIs. REST APIs (v1) support more features than HTTP APIs, while HTTP APIs are designed with minimal features so that they can be offered at a lower price. For instance, calculator.aws shows that 10 millions of requests cost 10 USD/month (Region: US East) whereas REST APIs costs 35 USD/month.
Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/apigw-http-api-lambda-ts-cdk
Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
- Create an AWS account if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
- AWS CLI installed and configured
- Git Installed
- Node and NPM installed
- AWS Cloud Development Kit (AWS CDK) installed
- Docker installed
- Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
git clone https://github.com/aws-samples/serverless-patterns
- Change directory to the pattern directory its source code folder:
cd apigw-http-api-lambda-ts-cdk
- From the command line, use npm to install the development dependencies:
npm install
- To deploy from the command line use the following:
npm run deploy
- Optional If you do not use the default profile in your configuration for aws credentials, you must edit your scripts section in the
package.json
, replacing<YOUR_PROFILE_NAME>
with your named profile:{ "scripts": { "deploy": "cdk deploy --profile <YOUR_PROFILE_NAME>", "destroy": "cdk destroy --profile <YOUR_PROFILE_NAME>" } }
The solution works as follow:
- CDK will provision an Amazon API Gateway HTTP API and a sample Lambda function.
- It will integrate the Lambda function to the HTTP API using the route "/"
- Finally, it will return the HTTP API URL in the console. (So you can test the deployment)
- After deployment, the output shows the API Gateway URL with the Lambda integration, for example:
HttpApiLambdaStack.HttpApiURL = https://<random id>.execute-api.<region>.amazonaws.com/
. - Accessing the URL in a browser, you see:
Hello World
.
- From the command line, use the following in the source folder
npm run destroy
- Confirm the removal and wait for the resource deletion to complete.
Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0