Performance optimization: skip Lambda functions
There's a popular saying in Serverless world: "Use lambda functions to transform, not transport" [here's one of the sources]. Lambda functions we built the first day of this workshop simply transport the data to DynamoDB table. We optimized a performance of our app, but can we go a step further and remove these Lambda functions? There's no cold start if we do not have a function.
Beside triggering Lambda functions, API Gateway has a few other types of integration. As explained here, API Gateway support the following integration types:
AWS_PROXY
: This type of integration lets an API method be integrated with the Lambda function invocation action with a flexible, versatile, and streamlined integration setup.AWS
: This type of integration lets an API expose AWS service actions.HTTP
: This type of integration lets an API expose HTTP endpoints in the backend.HTTP_PROXY
: The HTTP proxy integration allows a client to access the backend HTTP endpoints with a streamlined integration setup on single API method.MOCK
: This type of integration lets API Gateway return a response without sending the request further to the backend.
This means we can integrate API Gateway with DynamoDB directly, without Lambda function. To do so, we'll need to write a VTL template.
VTL, or Apache Velocity Template Language, is an alien language (just kidding, it's a Java-based template engine) that allows us to do some simple transformations on our API requests, and to save them directly to the DynamoDB without invoking a Lambda function.
Task
Your task is to remove a Lambda function that saves new expenses to the DynamoDB, and replace it with VTL template that will do the same. To do that you'll need the following steps:
- Analyze your Lambda function, and see the format required by our DynamoDB table.
- Remove the Lambda function from the CloudFormation template and replace it with the VTL template.
- Make sure the API Gateway has permission to talk directly to the DynamoDB table.
Hints
...