“Chalice is a framework for writing serverless apps in python”. Of course, based on AWS. The main reason why it interested me is that Chalice allows unique a lot of infrastructure boilerplate code.
Normally during development serverless-based application IaC tools like Pulumi or Terraform need a declaration of all needed resources ( API Gateway, API Endpoints, Stages, Deployment, Lambda, Role for Lambda, etc). In a declarative style that is normal — if you want something, declare it. But in the case of delivering serverless applications sometimes infrastructure code takes more than 35% of the project and looks almost the same. Chalice comes with help! It automatically generates: Lambda declaration, a role for Lambda, API declaration, integration between them, and API stage.
To explore Chalice I decided to make a simple serverless app. This app allows to add users to the Dynamo DB table using Lambda. And Lambda is integrated with API Gateway and requests are authenticated by Cognito Authorizer.
Implementation of this app took me ~30 min, from knowing nothing about Chalice to deploying a working app on AWS. Implementation of the same infrastructure using IaC tool which I know would take me about 3 hours maybe more. But in my app, not everything is covered by chalice code, Dynamo DB Table, and Cognito User Pool were created outside chalice because Chalice does not support it. Hopefully, policy for Lambda Role can be provided in Chalice config and Pool Authorizer can be created in few lines of code by providing arn of Cognito User Pool.
authorizer = CognitoUserPoolAuthorizer(
@app.route(‘/users’, methods=[‘POST’], authorizer=authorizer)
Despite the creation of every resource is not supported, but integration is very easy.
It interested me so additionally, I looked at Chalice documentation and tutorials in the context of using different resources and usability Chalice in microservices. And I discovered some features that make Chalice a useful framework.
- testing API locally
- exporting URL of deployed API stage
- exporting infrastructure to Terraform or CloudFormation
- invoking lambda and getting lambda logs from terminal
- generating swagger with x-amazon-apigateway-integration
Based on this research I have some conclusions.
AWS Chalice is a great tool for
- Personal projects — it is very easy to use, even if you have minimal knowledge about AWS. And if you know something about AWS and IaC, Chalice allows you to finish your project faster by taking care of code and some resources.
- Lambda based app with simple infrastructure — media query is an example application provided by Chalice doc which perfectly shows the advantage of using Chalice in an application using only Lambdas, API Gateway, s3, etc
- Early-stage of projects — if you have a plan to have API Gateway integrated with Lambda even if some features you want are not supported. It takes much less time to create a Chalice app and export it to your IaC tool than to do it on your own.
My research repository: gitlab.com/maciej.golebiowski/chalice-api/