Skip to main content

TypeScript Lambda

Deploy TypeScript lambda to AWS with ease.

Features

  • Write AWS Lambda functions in TypeScript
  • TypeScript is automatically transpiled and bundled into JavaScript using deno bundle.
  • Automatically bundle source code and other files into .zip archives for Lambda deployment
  • Automatically creates a dedicated IAM role for each Lambda function

Source Code

import { AwsStack } from '@dinghy/tf-aws'
import { LambdaFunctions } from '@dinghy/tf-aws/lambda'

export default () => (
<AwsStack>
<LambdaFunctions />
</AwsStack>
)

Outputs

Resource types

List of resource types used by this stack, in approximate order of creation:

  1. aws_lambda_function
  2. aws_iam_role
  3. data.archive_file

Steps to try

Install dinghy-cli

If you haven't already:

curl -fsSL https://get.dinghy.dev/install.sh | sh

Sample Screenshot

Prepare source code

Create my-lambda.tsx and other files with content from above.

curl -fsSL --create-dirs -o typescript-lambda/my-lambda.tsx https://raw.githubusercontent.com/dinghydev/dinghy/main/sites/www/src/docs/examples/show-cases/typescript-lambda/my-lambda.tsx
curl -fsSL --create-dirs -o typescript-lambda/dinghy.config.yml https://raw.githubusercontent.com/dinghydev/dinghy/main/sites/www/src/docs/examples/show-cases/typescript-lambda/dinghy.config.yml
cd typescript-lambda

curl -fsSL --create-dirs -o src/lambdas/alb-handler.ts https://raw.githubusercontent.com/dinghydev/dinghy/main/sites/www/src/docs/examples/show-cases/typescript-lambda/src/lambdas/alb-handler.ts
curl -fsSL --create-dirs -o src/lambdas/api-gateway-handler.ts https://raw.githubusercontent.com/dinghydev/dinghy/main/sites/www/src/docs/examples/show-cases/typescript-lambda/src/lambdas/api-gateway-handler.ts

Preview the actions

Run dinghy tf diff to preview the Terraform actions that will be performed.

info

Make sure your AWS credentials are configured before interacting with AWS services.

dinghy tf diff

Sample Screenshot

Apply the actions

Run dinghy tf deploy to apply the changes and provision your resources.

dinghy tf deploy

Sample Screenshot

Invoke the lambdas

To test your newly deployed Lambda functions, use the dinghy aws command.

dinghy aws lambda invoke --function-name alb-handler --region us-east-1 --cli-binary-format raw-in-base64-out --payload "{\"key\":\"value\"}" response.json

Sample Screenshot

Develop with devcontainer

You can launch a fully functional development environment by opening the project in a VS Code DevContainer:

dinghy dc

Destroy resources

After experimenting, run dinghy tf destroy to remove all resources created in the previous steps.