Skip to content

Typescript Lambda Boilerplate

Known Vulnerabilities Known Vulnerabilities

Quality gate

❗️ Contributors: See Development

The boilerplate serves as the starting point for rolling out a new Lambda. The boilerplate includes

  • Terraform
  • Terraform CDK in TypeScript
  • Example Lambda Handlers and common interfaces, utilities, etc.

The following patterns are shown in the boilerplate in Terraform, Terraform CDK in TypeScript, and TypeScript Lambda handlers.

  • SNS consumer
  • SQS consumer
  • CRON job
  • Utilizing ElastiCache in a Lambda
  • API Gateway integration

Pre-Requisites

Getting Started: Build out Lambda

This assumes you have the pre-requisites already configured, an AWS Profile configured, and a KMS Key admin role. For more information on how to configure an AWS Profile on your workstation, please see Adding a profile by editing the shared AWS credentials file

Compile and build the Typescript Lambda code. Navigate to the root of the repo to run the following commands.

  1. Install Lambda packages:
    make bootstrap-lambda
    
  2. Build the Lambda:
    make build
    

Terraform to deploy your Lambda

Once you have completed the steps in Getting Started, you will need to configure the terraform dependencies.

⚠️ This does not have a backend configured. See Backend configuration for more information.

  1. Navigate to aws-lambdas/terraform:
    cd aws-lambdas/terraform
    
  2. Set your AWS Profile environment variable:
    export AWS_PROFILE=<profile_name>
    
  3. Configure your local tfvars file.

    example.tfvars
    1
    2
    3
    4
    profile = "<profile_name>"
    kms_key_admin_arns = [
      "arn:aws:iam::<account_id>:role/<kms_admin_role_name>"
    ]
    

    This file should include:

    • The profile variable override
    • The kms_key_admin_arns variable override. This is for additional IAM roles to map to the KMS key policy for administering the KMS key used for SSE.
  4. Initialize:

    terraform init -var-file=example.tfvars
    

  5. Plan:
    terraform plan -var-file=example.tfvars
    
  6. If the plan looks good, run apply:
    terraform apply -var-file=example.tfvars
    

Creating additional Lambdas

In the Lambda module's README, there is a usage example you can reference to create additional resources in the terraform root's configuration.

Backend configuration

Since the code contained in this repo is only intended to serve as a boilerplate, the local backend is being used.

  • The local backend keeps the state local. These files are ignored in the repo's .gitignore. DO NOT remove the state files from the .gitignore since the state file may contain sensitive values.

For more information on backends, see the Terraform docs list of available backends.

Development

Quality Control MUST be configured prior to making any commits.

Preferred workstation setup can be found in Confluence.

Quality Control

This repo leverages Pre-Commit to ensure code quality and standardization.

To get started, install pre-commit:

pip install pre-commit

Once pre-commit is installed, run pre-commit install from the root of this repo. This executes prior to commits to the repo.

Authors

This project is authored by below people

  • SourceFuse