Monday, September 25, 2023

Synthetic Canaries for API Gateway – I

Last February, AWS added support for creating canaries for API Gateway to Cloudwatch Synthetics, which I’ve been using lately to monitor some REST APIS successfully.

Let’s review some technical concepts first:

  • Canaries: Node scripts that run on schedule to monitor endpoints, following the action path of your users. Canaries create Lambda functions using Node.js as a library, working with HTTP/HTTPS.
  • CloudWatch Synthetics: allow to create canaries without coding, just using templates without writing any code. It’s really easy to implement, and you can use, and you should, use Cloudformation.

Canary Dashboard, by

Problem to solve

After some hard work, now we have our brand new Serverless App deployed and ready to be tested, comprised of a REST API and a Microfrontend – Cloudfront + S3.

Serverless App, by

We need to monitor our endpoints for latency and resiliency; how do we do it right away? I have already answered the question: creating a synthetic canary.

Implementing a Canary

You can find the Canaries dashboard in the AWS console:

Cloudwatch > Insights > Application monitoring > Synthetic canaries

Image by

Creating a canary for API gateway from the console it’s really straightforward; you are given two options: select an API Gateway API and stage or a Swagger template.

Image by

We are presented then with a series of options:

  • Selection of the API-Gateway in the present Account/Region
  • Selection of Stage
Image by

The endpoint URL should be populated automatically:

Image by

The next step, adding a HTTP request, is also straightforward. The configuration – parameters, headers – depends on the method that is being tested:

Image by

Now you can finalize the creation of the canary:

  • Runtime version: you can leave the default version.
  • We are shown the generated code of the Lambda function implementing the canary.
  • Enviroment variables: variables to pass to the Lambda function.
  • Schedule: different ways to execute the canary. In this case, we choose Run continuosly.
Image by

In the following screen, we can see the canary that has been created and have been in execution for a while:

Image by

Finally, a few metrics are shown: Duration, Errors (4xx), Faults (5xx).

As promised, canaries are really easy to implement.

Final Architecture

Serverless Web App + Canary

Adolfo Estevez
A Estevez
Cloud & Digital Evangelist | AWS x 13 Certified | GCP x 6 | Serverless | Machine Learning | Analytics |

Related Articles

Leave a Reply

Latest Articles

%d bloggers like this: