Skip to content

laxmanvijay/aws-sam-nodejs-typescript-template

Repository files navigation

This is a template for AWS SAM Node.js Typescript support.

It is configured with lambda layers in dependency-layers folder.

This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders.

  • src/hello-world - Code for the application's Lambda function.
  • src/hello-world/tests - Unit tests for the application code.
  • infra-templates/master-template.yaml - Entrypoint of infra templates.
  • codebuild-template - Sample buildspec.yaml
  • samconfig.toml - Config parameters for sam commands.
  • eslint - Configured with AirBnb rules.
  • babel.config.js - To enable Jest framework to support typescript.
  • precommit-hook - perfoms linting and unit testing.

Deploy the sample application

The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API.

To use the SAM CLI, you need the following tools.

To build and deploy your application for the first time,

  • Add the appropriate AWS_PROFILE in your env.

  • Provide a bucket name in samconfig.toml file.

  • Run the following in your shell:

npm run deploy

To test locally

npm run runApiLocal

The SAM CLI reads the application template to determine the API's routes and the functions that they invoke. The Events property on each function's definition includes the route and method for each path.

      Events:
        HelloWorld:
          Type: Api
          Properties:
            Path: /hello
            Method: get

Add a resource to your application

The application template uses AWS Serverless Application Model (AWS SAM) to define application resources. AWS SAM is an extension of AWS CloudFormation with a simpler syntax for configuring common serverless application resources such as functions, triggers, and APIs. For resources not included in the SAM specification, you can use standard AWS CloudFormation resource types.

Unit tests

Tests are defined in the hello-world/tests folder in this project. Use NPM to install the Mocha test framework and run unit tests.

npm run test

Linting

To perform linting in the src folder, run:

npm run lint

Cleanup

To delete the sample application that you created, use the AWS CLI. Assuming you used your project name for the stack name, you can run the following:

aws cloudformation delete-stack --stack-name nodejstest

Resources

See the AWS SAM developer guide for an introduction to SAM specification, the SAM CLI, and serverless application concepts.

Next, you can use AWS Serverless Application Repository to deploy ready to use Apps that go beyond hello world samples and learn how authors developed their applications: AWS Serverless Application Repository main page

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published