I love developing TypeScript Applications. I hate deploying TypeScript applications to AWS Lambda.
This project serves as an example for deploying TypeScript applications to AWS using a little bit of custom configuration and the serverless framework.
For a better understanding of the project, I suggest reading the associated articles:
- Authenticate Lambda Requests with ALB and Google OAuth: Part 1.
- **Authenticate Lambda Requests with ALB and Google OAuth: Part 2
If you learn by doing, install the project dependencies and run either one of the following commands:
$ yarn build-deploy
$ npm run build-deploy
This command will build the TypeScript services defined in the src/
directory and deploy them to AWS. When you go to the CloudFormation service in the AWS Console, you'll see a new stack named web-forum-ts-dev
, which is defined in the serverless.yml
. The stack will contain THREE main resources:
- ForumThreads: DynamoDB Table.
- CreateForumLambdaFunction: AWS Lambda Function.
- CreateThreadLambdaFunction: AWS Lambda Function.
To test the functions, here's some sample input
// Create Forum
{
"ForumName": "Fix The Title",
"User": "Jane Doe",
}
// Create Thread
{
"ForumName": "Fix The Title",
"ThreadTitle": "NewThread",
"User": "Jane Doe",
"PostedTime": "2021-01-01T22:00:00.000",
"Message": "First thread!!!"
}
Please note that the ForumName
provided in the payload for the CreateThread Lambda must be a valid Forum Name, meaning it must exist in the table.
This application uses a DynamoDB Single Table design pattern for its backend. I wrote an article explaining how I modeled the data for this application, and if you're interested, you can read that here.
To minimize the risk of information overload, this release contains just two Lambda services:
- Create a new Forum.
- Create a new Thread within an established Forum.
Additionally, I left out unit tests and formatters/linters so that we can focus on the important files for deploying our TypeScript application.