With the Serverless Framework v1.41.0 release, we’re adding AWS X-Ray Tracing support for API Gateway, which complements the AWS tracing story and makes it possible to trace incoming events from API Gateway all the way through your Lambda functions. Our new version also adds support for multiple API Gateway usage plan and key definitions as well as lots of enhancements for local function invocations via Docker. In addition to that, we also addressed a couple of bug fixes and enhancements. 1 bug fix and 7 enhancements were merged and are now available in our v1.41.0 release.
AWS API Gateway is one of the central services used in many serverless applications. Interactions with an API Gateway-driven serverless backend start with an event which is triggered via an HTTP request and then re-routed to the corresponding AWS Lambda function.
It would be great to monitor and trace requests through the service-stack to better understand how requests are processed and where they spend most of their lifetime.
In one of our previous Serverless Framework releases we introduced AWS X-Ray Tracing for AWS Lambda. With this post, we now complete the picture by adding AWS X-Ray Tracing support for API Gateway.
Enabling tracing for API Gateway is as easy as enabling the corresponding config on the provider
property:
provider:
tracing:
apiGateway: true
X-Ray tracing works best when it’s used across multiple AWS services. If you’re using X-Ray Tracing for API Gateway you might want to enable it for your Lambda functions as well:
provider:
tracing:
apiGateway: true
lambda: true
This way you can get more insights into your API Gateway → Lambda setup when using the X-Ray Tracing Service Map
IMPORTANT: Due to CloudFormation limitations it's not possible to enable AWS X-Ray Tracing on existing deployments which don’t use tracing right now.
Please remove the old API Gateway and re-deploy it with tracing enabled if you want to use AWS X-Ray Tracing for API Gateway.
Sometimes it’s useful to limit access to your API Gateway when exposing it to the public. In previous versions of the Serverless Framework this could be easily done via API Keys and usage plans:
provider:
name: aws
apiKeys:
- keyOne
- keyTwo
usagePlan:
quota:
limit: 5000
offset: 2
period: MONTH
throttle:
burstLimit: 200
rateLimit: 100
The initial implementation which supported one usage plan and multiple API Keys was usually enough for simple API Gateway setups.
However in production setups one usually needs more flexibility. It’s very common to have different types of usage plans for different user types, such as “free” plan users and “paid” plan users.
The Serverless Framework v1.41.0 adds support for multiple usage plans. Multiple API Keys can be assigned to each usage plan:
provider:
name: aws
apiKeys:
- free:
- freeKeyOne
- freeKeyTwo
- paid:
- paidKeyOne
- paidKeyTwo
usagePlan:
- free:
quota:
limit: 5000
offset: 2
period: MONTH
throttle:
burstLimit: 200
rateLimit: 100
- paid:
quota:
limit: 50000
offset: 1
period: MONTH
throttle:
burstLimit: 2000
rateLimit: 1000
Serverless Framework recently added support for local function invocation via Docker, meaning that every AWS Lambda runtime can now be invoked locally in a Docker container.
Serverless Framework v1.41.0 adds support for: function environment variables; access to function dependencies; lambda layer download caching; and Docker argument passing.
As always, we appreciate each and every one of you that use and contribute to the Framework and Serverless ecosystem!
Philipp Müns is a core developer at Serverless, Inc.
Product