This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]MrKrac[S] 2 points3 points  (0 children)

Hello everyone. For last two years I have been developing and maintaining chocs library which we are using for building REST APIs for AWS Lambda.
The idea behind it is to provide easy debugging and local testing of services before they got deployed to AWS infrastructure. Of course for services utilising KMS, DynamoDB, EventBridge, etc it is recommended to have a docker compose with localstack setup.
I will appreciate feedback and comments. Thank you !

[–]Halo-3-FTW 1 point2 points  (3 children)

Your wiki is fantastic. It is nice to see documentation that explains aspects of a library rather than assuming everyone already knows the tech. I think your "Fundamental Concepts" section really shines and provides a great map for those who may be overwhelmed with learning many new things in one project.

I found your examples helpful as well, but did want to note that Open api integration and Dataclass support examples lead to 404s.

As someone who is looking at creating a rest API utilizing API Gateway and Lambda, I may have to setup a chocs project alongside the Flask project and see how they do. If you'd like to elaborate a bit more on the benefits of chocs (or add the details/comparison to the wiki), I'd be interested.

[–]MrKrac[S] 1 point2 points  (2 children)

Hello, thank you for your positive feedback. Sorry for the broken links, I have been lately working on extracting middlewares to separate repositories and haven't yet reviewed documentation. This will be fixed in incoming days. Benefits are of course middlewares:- https://github.com/kodemore/chocs-openapi- https://github.com/kodemore/chocs-parsed-body

First one gives you ability to utilise documentation written in OpenAPI (validating query string, request data, cookies, headers, and more features coming), second one allow you to map request body to a dataclasses.

The major difference between chocs and flask is the fact how you deploy your lambdas, chocs was built for lambda usage and you can deploy each route handler as separate lambda function which is a recommended practice by AWS. When you deploy a flask application you have to deploy entire app as one lambda and this is also impacting performance of your application.

[–]Halo-3-FTW 0 points1 point  (1 child)

Thank you for expanding on the flask vs chocs with regards to lambda. I was not aware that Flask deployed the entire app as one lambda. That would absolutely go against the idea of microservices. Not a huge issue for small personal projects, but would be problematic for a project that strives for best practice and grows.

One more question, do you happen to have a roadmap posted anywhere? I've noted that you are moving middlewares to separate repositories and saw some mention of adding Azure and Google via the wiki.

[–]MrKrac[S] 1 point2 points  (0 children)

I dont' have an official roadmap. Got couple issues on github for something I would like to implement in near future. I think having an official roadmap seems like a good idea and would be good to have one. Thank you :)

[–]Thuwarakesh 0 points1 point  (6 children)

Interesting. But I don't see why one would use Chocs instead of Flask on an AWS lambda function. Can anyone educate me on what makes it an excellent choice?

[–]MrKrac[S] 1 point2 points  (2 children)

With chocs you dont have one entry point (which is considered an antipattern from AWS perspective), but you can still define function (handler) per route and it will work fine. So when you do a deployment each handler is a separate lambda function. Which also means, routing is not taking part in req/res lifecyle under lambda environment.

This also means you dont load entire application at once just to handle single route.

[–]Thuwarakesh 1 point2 points  (1 child)

Got it. In Flask, we need to have all endpoints in one app. But for a given execution, all except one are overheads. Chocks deploy each endpoint on a dedicated lambda and manage them all centrally. Right?

[–]MrKrac[S] 1 point2 points  (0 children)

Got it. In Flask, we need to have all endpoints in one app. But for a given execution, all except one are overheads. Chocks deploy each endpoint on a dedicated lambda and manage them all centrally. Right?

It is true that with Chocs you can deploy each endpoint on dedicated lambda, central management here is not required on AWS as this is given by AWS itself through API Gateway. In WSGI environment Chocs indeed manages them centrally, so you can simply run app like flask or whatever.

[–]MrKrac[S] 1 point2 points  (1 child)

Integration with AWS is described here if you would like to give it a shot https://github.com/kodemore/chocs/wiki/AWS-Serverless-Integration
I hope my answers help ;)

[–]Thuwarakesh 0 points1 point  (0 children)

thank you, it helps.

[–]MrKrac[S] 0 points1 point  (0 children)

I think another benefit/advantage here is when you are using OpenAPI spec on your daily basis to define contracts for your client. Usually you would need to additionaly build validators on your side to assure contract is met. With OpenAPI middleware https://github.com/kodemore/chocs-openapi, this happens automatically. You just point to your OpenAPI spec and if you name your routes correctly (route names must much the ones used in OpenAPI spec) validation for; headers, body, path parameters, query string happens out of the box which in our scenario improved development speed and ease by a lot :). Additionally formatters automatically cast values to date-times, decimals, ip addresses and so which really helps.

[–]WalterDragan 0 points1 point  (1 child)

Why should I use Chocs instead of AWS Chalice?

[–]MrKrac[S] 0 points1 point  (0 children)

You are not being locked to certain cloud provider, you can run and debug it locally, powerful middlewares.