Amazon API Gateway!

Jared Matta
4 min readSep 21, 2020

Amazon Web Services is cloud computing, which means all the computing that you do is done on the cloud or the web. The advantages of cloud computing are fixed cost, economies of scaling, more bandwidth available, and virtualization. There are many Cloud computing services such as Microsoft Azure, and Google Cloud, but we will be focusing on AWS today, more specifically making a REST API on Amazon Web Services, with Amazon API Gateway.

You can start by logging into Amazon Web Services and creating an account if you haven’t already( Free options are available). Next search or find Amazon API Gateway in the many AWS services there is to offer. You can choose between REST or Web Sockets, but we will be setting up our API using REST as the API type, in this blog. Initially, AWS will pre-populate our API with a Pet Store API defined using Swagger 2.0. Swagger is similar to a WSDL in the SOAP convention, but in short will help import an API (in JSON format) from a different type or format, to help create our API. Let’s get started by hitting that import button at the bottom with or default API example.

You will be redirected to the next screen where you can view your API. In order for our API to work it must be deployed over the cloud, So select Deploy API.

To get people to actually use our API we must set it up the deployment by making two decisions. One being the Deployment Stage, and Two the Deployment Description. Since we don’t yet, we have to define a New Stage. Let’s call the Stage Name: “Test”, and the Stage Description: “Test”, for demonstration purposes. Deployment Description can be left blank, for the time being. Now hit deploy and let’s move on.

At the top we have a invoke URL for our Test Deployment, let’s take that and copy it into our text editor.

We can import this Swagger into handy Postman by heading back to AWS, and clicking the export button. Here we can see a couple of export options, one being postman, which we want to view in JSON format. Copy this text and head over to Postman, where we click Import/type of Raw Text and hit continue. On this prompt, we can keep our defaults and just hit import. Now if we click on the Define view and checks our Collections we can see our swagger file has been brought into Postman, with 6 requests attached. If you go back to AWS and click on resources you’ll notice we have two endpoints of /pets, and /{petid}.

Back in our Text editor, we can configure our test endpoints from our Base URL, such as seen below. You can copy the last endpoint and pop it into your browser, to see if the endpoint of a pet with the id of 2 works. You can play around with the ids’ from here, but we should receive a cat as a pet with a price of $124.99.

Heading back to Postman, let’s find our cat, using our Get Requests. In our Requests folder, you will find a folder labeled {pet id} with a Get Request, open this. We can find our cat by adding our Base URL from AWS or your text editor and giving the petid a value of 2, and hitting send. Hooray! we found our cat.

From here we have a view of using REST API inside Amazon REST services, using API gateway. You could have just as easily created your own API, even better we can utilize the database services that Amazon has to offer. I hope you enjoyed this intro into Amazon Gateway, and I hope you always stay learning. Thank You.

--

--

Jared Matta

Flatiron Graduate, Full-Stack developer on his job search. I love working with Javascript and React.