I have a /catalogue API backed by AWS Lambda, currently running version 1. As part of my CI/CD pipeline, I publish the OpenAPI definition and Lambda deployment package to Amazon S3. I want to release version 2 seamlessly, with no downtime and ideally a way to test it gradually before sending all traffic to the new version. What deployment pattern should I use?
3 Answers
A typical pipeline is: build the Lambda package, deploy the code, publish a new Lambda version, shift a small amount of traffic, monitor it, then require approval before moving to 50% and finally 100%. If you need both versions exposed as separate API contracts, use separate routes or API stages and route them through a custom domain; otherwise, an alias with weighted traffic is usually the simpler approach.
Use a canary or phased rollout instead of moving everything at once. Deploy and publish version 2, send a small percentage of traffic to it, and monitor errors, latency, throttles, and business metrics. If everything looks healthy, gradually increase the share until version 2 receives 100%. If problems appear, shift the alias back to version 1 for a quick rollback.
Publish the new Lambda code as a numbered, immutable version, then point an alias such as ACTIVE_VERSION to that version. Configure API Gateway to invoke the alias rather than an unqualified Lambda function ARN. For the next release, update the alias to the new version, which lets you switch versions without changing the API configuration or interrupting requests.

That makes sense—I hadn't realized API Gateway could consistently target the alias instead of the Lambda function version directly.