Wednesday, June 7, 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 MNUBE.org

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 MNUBE.org

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 MNUBE.org

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 MNUBE.org

We are presented then with a series of options:

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

The endpoint URL should be populated automatically:

Image by MNUBE.org

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

Image by MNUBE.org

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 MNUBE.org

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

Image by MNUBE.org

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 Estevezhttps://mnube.org
Cloud & Digital Evangelist | AWS x 13 Certified | GCP x 6 | Serverless | Machine Learning | Analytics |

Related Articles

Leave a Reply

Latest Articles

error:
%d bloggers like this: