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:
- Create a basic API in API Gateway
- Deploy the API from API Gateway
- Export the API as a Swagger spec
- Import your Swagger spec into Assertible
- 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:
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:
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:
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
deployed to a
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:
A form will open prompting for the
stageto deploy the API. In API Gateway, a
stageis simply one location an API can be deployed, like a production or staging environment. Fill out the form with values for your API:
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
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:
Select Export as Swagger as either JSON or YAML:
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
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:
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:
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.
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:
- Build an API to expose a Lambda function
- Calling a deployed API
- Techniques to reduce api testing errors and improve your QA process.
- 4 common API errors and how to test them.
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
The easiest way to test and
monitor your web services
Reduce bugs in web applications by using Assertible to create an automated QA pipeline that helps you catch failures & ship code faster.Get started with GitHubSign up for free
New feature: Encrypted variables 10/30/2019
New feature: Smarter notifications 5/17/2019