Headstart Microservices Architecture using AWS Lambda in your favorite programming language (Node.js or Python or JAVA)

The way we build software has changed stupendously from Monolithic Architecture (MLA) using single programming language to a Microservices Architecture (MSA) where pieces of code developed in multiple different programming language that fits the problem in hand. Microservice has numerous benefits and encourages Single Responsibility Principle (SLP) with quick deployment and easy to change lifecycle without impacting the fatty software.

AWS offers easy way to implement microservices through RESTful APIs wrapped against AWS Lambda functions in a server less backend that can auto scale with built in security via its IAM. AWS offers 12 months free tier which enable you to get hands-on experience with AWS Cloud Services.

To demonstrate the power of AWS API Gateway & Lambda, I quickly dropped my flicker photo search node.js code as lambda function wrapped in AWS API Gateway and exposed it as REST API Endpoint.

CODE

AWS lambda does not support 3rd party npm so make sure to upload all of your 3rd party node_modules. AWS Lambda & API Gateway Getting Started guide will be your good head start.

API END POINT

POST https://www.getpostman.com/collections/9f4773dd73a512b92e7a

REQUEST BODY

{
"api_key":"4a9d265192929f69631c55b9a5bdf9bc",
"search_tags":"Raspberrypi",
"search_text":"Raspberrypi",
"search_limit":10,
"search_currentpage":1
}

POSTMAN SCREENSHOT

image

 

RESTful API 10 Best Practices I follow

Following are the SILVER BULLETS when I create REST APIs. These were originally published here in the year 2014 and the credits goes to them but my true salute goes to OMAR AL ZABIR who published with sample source in C# in his blog post Build Truly RESTful API and Website using Same ASP.NET MVC Code way back in 2012 where he talked about RESTful services naming conventions and leveraged the Controllers  from ASP.NET MVC exported as REST API without using API.NET WEB API using content negotiation and http header (point # 5 below)

REST-BET-PRACTICE

 

  1. Use nouns but no verbs
  2. GET method and query parameters should not alter the state
  3. Use plural nouns
  4. Use sub-resources for relations
  5. Use HTTP headers for serialization formats
  6. Use Hypermedia as the Engine of Application State (HATEOAS)
  7. Provide filtering, sorting, field selection and paging for collections
  8. Version your API
  9. Handle Errors with HTTP status codes
  10. Allow overriding HTTP method

Do not end here but head over to the above mentioned two blog posts to gain the internals.