danilop / lambda-rust-and-cdk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lambda, Rust, and CDK

This is an AWS CDK project in TypeScript building two AWS Lambda functions developed using Rust. It's meant as a showcase to share my experience of using Rust with AWS Lambda. I am interested in Rust because it is a very secure and efficient programming language.

Contents

The two Lambda functions are in the /resources folder:

Rust is a very efficient programming language that allows the two functions to run with very little memory and CPU usage. For example, they are both configured with the minimum allowed memory (128 MB). Because Lambda allocates CPU power in proportion to the amount of memory configured, this is also the minimum configurable CPU power. Both functions are are still very performant with a response time of about 1-1.5ms and an initialization time (cold start) of ~20ms for my-function and ~400ms for my-web-app.

The description of the stack is in the /lib/my-project-stack.ts file. This includes instructions to build my-function using a bundling container.

The instructions to build my-web-app are in the /resources/my-web-app/Dockerfile. The Dockerfile uses a multi-stage build to create an executable that is then passed to the final image. The only difference here to make this container image run in AWS Lambda is the COPY command from the Lambda Web Adapter image.

The cdk.json file tells the CDK Toolkit how to execute the app.

Requirements

To deploy this app (including the two Lambda functions) you need:

Rust and its compiler are not a requirement because duing the building process they are used inside containers.

Deployment

Use npm install to install CDK dependencies.

Then run cdk deploy and follow the interactive instructions.

Useful commands for the CDK project

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run test perform the jest unit tests
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk synth emits the synthesized CloudFormation template

About

License:Apache License 2.0


Languages

Language:TypeScript 37.6%Language:Rust 36.4%Language:JavaScript 17.0%Language:Dockerfile 8.9%