Coder Social home page Coder Social logo

serverless-typescript-demo's Introduction

Serverless Typescript Demo

Architecture diagram

This is a simple serverless application built in Typescript and uses Node.js 14 runtime. It consists of an Amazon API Gateway backed by four AWS Lambda functions and an Amazon DynamoDB table for storage.

Requirements

Software

Within folder is the products npm project. This project contains all the code for all four Lambda functions. It uses the hexagonal architecture pattern to decouple the entry points, from the main domain logic and the storage logic.

Deployment

Deploy the demo to your AWS account using AWS CDK.

npm install
cdk deploy

The command cdk deploy will first build the products TypeScript project using a docker build image esbuild. Then it will use AWS CloudFormation to deploy the resources to your account.

CDK will create an output of the API Gateway endpoint URL for future use in our load tests.

Load Test

Artillery is used to make 300 requests / second for 10 minutes to our API endpoints. You can run this with the following command.

./load-test/run-load-test.sh

This is a demanding load test, to change the rate alter the arrivalRate value in load-test.yml.

Monitoring

This app leverages the AWS Lambda Powertools for TypeScript to emit monitoring data.

Logs

Using this CloudWatch Logs Insights query you can analyse the latency of the requests made to the Lambda functions.

This query returns the last 20 logs of the Lambda function that returns the products list.

fields resource_path, message, timestamp
| filter service = 'serverless-typescript-demo'
| filter function_name LIKE /GetProducts/
| sort @timestamp desc
| limit 20

This query returns the last 20 logs that contain an error or a warning.

fields resource_path, message, timestamp
| filter service = 'serverless-typescript-demo'
| filter level = 'WARN' or level = 'ERROR'
| sort @timestamp desc
| limit 20

This query returns the last 20 logs related to a specific product ID.

"63f74370-1d0b-49f8-be86-586efdef13be"
| fields resource_path, message, timestamp
| filter service = 'serverless-typescript-demo'
| sort @timestamp desc
| limit 20

This query returns the last 20 logs of invocations that experienced a cold start.

fields resource_path, message, timestamp
| filter service = 'serverless-typescript-demo'
| filter cold_start = 1
| sort @timestamp desc
| limit 20

This query separates cold starts from other requests and then gives you p50, p90 and p99 percentiles.

filter @type="REPORT"
| fields greatest(@initDuration, 0) + @duration as duration, ispresent(@initDuration) as coldStart
| stats count(*) as count, pct(duration, 50) as p50, pct(duration, 90) as p90, pct(duration, 99) as p99, max(duration) as max by coldStart

Sample test result

๐Ÿ‘€ With other languages

You can find implementations of this project in other languages here:

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

serverless-typescript-demo's People

Contributors

amazon-auto avatar ckuijjer avatar dependabot[bot] avatar jeastham1993 avatar lucamezzalira avatar nmoutschen avatar roman-boiko avatar saragerion avatar spalladino avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.