Template for creating AWS Lambda APIs using CDK.
- Clone the template repository from https://github.com/azumbro/AWSLambdaAPICDKTemplate.
- Navigate to the cloned repository and install Node modules by running
npm install. - In
lib/lambda_api-stack.js, add the target AWS region and account ID to theACCOUNT_SETTINGSobject. - In
lib/lambda_api-stack.js, add an entry toLAMBDA_FUNCTIONSfor each lambda function/API to create as part of the stack.- The
namefield specified the name of the lambda/API. - The
handlerfield points to the handler file and function that will serve as the entry point to the lambda/API; these handles should be located in JS files within theresourcesdirectory. For example, a value ofapi1_handler.mainwould look for an exportedmainfunction in theresources/api1_handler.jsfile. - The
allowedOriginsfield specifies a list of domain origins that can call the lambda/API. An entry of "*" allows for all domains to call the lambda/API.
- The
- Write your lambda/API business logic in the handler functions. A basic example has been provided in
api1_handler.main. - When ready to deploy your lambda/API, run
npm run cdk deploy. This will create the relevant CFN stack and lambda functions in your AWS account. - Get the URL(s) for calling your lambda/API(s). These can be found in the AWS console by navigating the the lambda function list, selection a lambda function, and looking for the value under "Function URL" in the overview panel.