In the previous article we discussed one way to create
TypeScript aws lambda using
In the current article we’ll take a look at even easier way to achieve the same. We will use
sam cli only. It maybe one of the fastest and easiest way to create typescript aws lambda.
Steps to create TypeScript lambda using
Initiate aws lambda structure using
Just like in the previous article we will use the following command to initiate our
This time when
sam cli asks for
AWS quick start application templates we choose option 8:
Quick Start: App Backend using TypeScript
As a result the following structure will be created:
Check generated folder and update logic according to your need
When we check
package.json file in
app folder we will see something like this:
As you can see there are already scripts for
testing!, compilation and linting. It’s very handy to have everything in place already, right? :-).
- there are examples of handlers in
mochaunit tests in
app/tests/appsthat can help you be up to speed really fast
- interfaces that are useful for testing and general understanding of aws api gateway structure in
app/src/common/apigateway(although the same classes you can use from aws libraries by installing
@types/aws-lambdanpm package, which is much more reliable)
- last, but not least, an example of
dynamoDbRepositorywhich is pretty basic though
Apart from source code you can find
Makefile that makes it easy to build your source code and be prepared for deployment.
And with everything said above you can run the following commands to deploy your lambda to aws account:
sam build sam deploy --guided
SAM makes it super easy to create
aws typescript lambda and along the way provides a good starting point for active development.