Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda + API Gateway Development Best Practices

We are a team of 5 developers and need some guidance on the best way to develop on AWS specifically using AWS Lambda, API Gateway, DynamoDB, and Cognito. We are looking for the best practices for development. How can 5 developers develop without stepping on each other toes? Is it better to have individual accounts and use cloud formation templates that can be used by each developer?

Or use the serverless framework and use a different environment for each developer? It looks like serverless provides the ability to deploy to various environments, but I believe the intent for different environments is for CI/CD where the same code can be moved through various SDLC or specific code can be pushed to a specific environment.

like image 470
JSONGagnon Avatar asked Aug 11 '26 05:08

JSONGagnon


2 Answers

I would recommend using Serverless Framework to improve developer productivity. Few of the practices we follow

  • Keep all the infrastructure changes in Serverless Framework generated CloudFormation stack template.

  • Create different API Gateway stages for each developer.

  • Utilize Serverless Plugins. E.g Serverless Offline, Severless DynamoDB Local & etc.

  • Use a NodeJS proxy, if you plan to setup hybrid development environment e.g Use Serverless Offline plugin emulating API Gateway and Lambda localy, S3 with Cognito in AWS.

  • Use a task runner like Gulp to automate starting web servers, deployment & etc.

  • Use environmental variables to store environment specifics.

Apart from this, its better to use a seperated AWS account for production. You can configure AWS organizations to simplify managing multiple accounts.

like image 127
Ashan Avatar answered Aug 12 '26 19:08

Ashan


At my company, we've been building 5~6 microserivces with Lambda + API Gateway + DynamoDB mostly, and came up with the some guidelines and template https://github.com/balmbees/lambda-microservice-template

For Environment Variables,
I recommend to do provider: name: aws runtime: nodejs4.3 environment: ${file(./env/${opt:stage}.yml)} in serverless.yml and just use process.env, which means putting environment variables in git repo, (such as /env/production.yml)
you can write your on CI/CD script to inject those variables when doing deployment only, but we just decided to do this since git repo is private anyway.

For Development Guideline,

Use Typescript.

Highly recommend it. seriously helpful to keep everything working, without writing crazy amount of test code to just make sure you don't make compile-catchable mistakes.

if you're thinking of making Restful API, checkout this also

like image 43
Kurt Lee Avatar answered Aug 12 '26 17:08

Kurt Lee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!