06/01/2017 Featured Cody Reichert

AWS's API Gateway is a great tool that makes it easy for developers to create and publish an API. In this post, I'll show you how to set up automated API testing and monitoring for all of your endpoints.

Amazon's API Gateway is a tool for developers to easily create, document, and publish APIs. As with any API, automated testing and monitoring provides another layer of security that your services are available and working as expected.

It's easy to create create an automated test suite for your API Gateway endpoints by exporting your API as a Swagger specification and importing it into Assertible.

In this post, I'll walk through creating a basic API Gateway example in AWS and setting up API testing, monitoring, and alerts in Assertible. Here's the steps we'll take:

  1. Create a basic API in API Gateway
  2. Deploy the API from API Gateway
  3. Export the API as a Swagger spec
  4. Import your Swagger spec into Assertible
  5. Set up automated monitoring and alerts

Create a basic API in API Gateway

Getting started with AWS API Gateway is easy and heavily documented. If you don't already have an AWS account, you can sign up for free. After signing in, navigate the API Gateway service page, and you should see a Getting Started screen:

  • On the API Gateway service page, click Getting Started:

    Getting started with AWS API Gateway

    This will take you to a Create new API page. For this example, I'll be set up the default Example API, which uses the Swagger PetStore example to create some default endpoints and HTTP methods.

  • Select the Example API and you will see a preview of the Swagger spec, then click Import:

    Swagger PetStore example in API Gateway

    If you have an existing API, or want to use this opportunity to start creating your own, that's perfectly fine - you don't have to use the default example.

  • After clicking Import to finalize your new API, you will see a preview of the endpoints and resources:

    Swagger PetStore example in API Gateway

You have a new API managed in AWS!

From here, you can explore the API's endpoints and experiment with request and response payloads. I won't get too in-depth about all of the API Gateway features, but these extended resources are great for learning more:

Deploy the API from API Gateway

Next, the API needs to be deployed to a stage make it publically available. This step is also required before the API can be exported from the console.

  • Click the Actions dropdown in the API Gateway console, and select the Deploy API option:

    Initiate an API deployment in AWS API Gateway

  • A form will open prompting for the stage to deploy the API. In API Gateway, a stage is simply one location an API can be deployed, like a production or staging environment. Fill out the form with values for your API:

    Initiate a deployment in AWS API Gateway

    After you've filled out the form to your liking, click Deploy.

Success! On the next page, you will see details about the API's deployment stage including an Invoke URL where your API can be accessed, and various other settings for managing your API.

With a new API created and deployed, we can export the API specification to a format that can be imported into Assertible.

Export the API as a Swagger spec

Assertible supports creating automated tests from a swagger spec, so you can export your API from the API Gateway console as a JSON or YAML Swagger spec and import it to get everything initially set up.

  • To export your API as a Swagger spec from API Gateway, find the Export tab on the stage's settings page:

    AWS API Gateway deployment

  • Select Export as Swagger as either JSON or YAML:

    AWS API Gateway deployment

And that's it. A file should be downloaded for your Swagger spec, which can be used n the next steps. Learn more about exporting an API from AWS and other API formats Assertible supports.

Import your Swagger spec into Assertible

Assertible will create API tests for each endpoint/method combination in your Swagger spec. If you don't have account already, you can create a free one here.

In the New Service form, choose Import a Swagger spec, and upload the file exported from API Gateway

Import a swagger spec into Assertible

A dry run of your endpoints, tests, and environments is shown before fully importing the spec. Click Create service and tests to finalize the import and go to your web service overview.

If you have an API that requires auth, headers, or other settings, explore some of these resources to help get your API tests passing:

Set up automated monitoring and alerts

With an initial set of tests created for the API, you can set up automated monitoring to run them on a schedule. Assertible support various types of API test automation (check out the docs), and for this example I'll set up hourly schedule monitoring.

  • Go to the Monitoring tab of your web service, and click Set up a schedule:

    Set up monitoring for an API in Assertible

    You can choose between hourly and daily schedules on the free plan, and start the monitoring at a specific time. When you've confirmed the details, click Create schedule.

    If you need more frequent schedules, you can upgrade your account.

  • After confirming, you will see an overview of your schedule, and can enable or disable any specific tests:

    Set up monitoring for an API in Assertible

The API tests are now passing and running a schedule! Now you can continue to configure the rest of your settings like hooks and alerts.

Assertible has support for sending API test results to a slack channel or sending emails after test runs. Both of these can be configured from the Hooks & Alerts page of the Settings tab on your web-service.

Continued reading

We've covered the basics of creating an API in API Gateway and setting up automated monitoring with Assertible, but there's plenty more to do. Check out some of these resources below to learn more about both:

Resources

Have any questions, questions, or something to add? Shoot me a message on Twitter and let me know. Check it out and sign up for a free Assertible account to start testing and monitoring your API Gateway.

:: Cody Reichert

Categories

Automate your QA pipeline

Define and test your web service with Assertible Track and test API deployments across environments Schedule API monitoring and failure alerts

Reduce bugs in web applications by using Assertible to create an automated QA pipeline that helps you catch failures & ship code faster.

Sign up for free