Stream your AWS API Gateway

This quick & easy tutorial aims to explain how to stream an API powered by AWS API Gateway using Streamdata.io in 4 steps.

Let’s start with an introduction to AWS API Gateway: It provides a managed service to enable developers to create, publish, maintain, monitor, and secure APIs. As we will see, it requires only a few clicks in the AWS Management Console, to create an API that acts as a “front door” for applications to access data, business logic, or functionality from your back-end services.

1 – Create a new API
First step required by AWS when getting started with their API Gateway is to create an new API:

create new api

Enter a name and click Create API

2 – Create a Method
After having clicked on Create Method, you first need to select the HTTP Verb of your API. We will choose GET as we only need an API to retrieve data.
Then, AWS ask you to select the Integration type. AWS provides many different Integration types to enable you to quickly expose an API from a Lambda function or many other AWS services (through the advanced option).
As we already have an HTTP Endpoint called http://stockmarket.streamdata.io/prices that mocks a market data feed, we will use AWS API Gateway in HTTP proxy mode.

create method

Click Save. AWS should display the Method Execution of your previously created API and you see something like that:

api method execution

There is a lot of interesting stuff here, clicking on the different block of the workflow will give you access to different features modify the behavior of your API. As an example clicking on Method Request gives you the ability to change the Authorization setting or inject additional Query Parameters and Request Headers.
We will not go through all the possibilities but I invite you to take a look at AWS API Gateway Documentation, it will give you a better idea of all the capabilities.

3 – Deploy your API
Now that everthing is setup let’s deploy our API but simply clicking on Deploy API. AWS will prompt you to select a Deployment stage. If you do not have one yet, create it by selecting “New stage” in the dialog box.

deploy api

5-aws-api-gw-new-stage

Then, click Deploy.

After having successfully created your stage, AWS gives you access to additional stage settings such as Caching, CloudWatch Alarms, Rate limiting. You can also export your API definition compatible with Swagger format. Nice!
The most important thing for us is to get the Invoke URL from which your API can be called.

Let’s make a quick test with cURL:

curl "https://<your-subdomain>.amazonaws.com/<stage-name>"

You should get a response like this:

[{"title":"Value 0","price":56,"param1":"value1","param2":"value2","param3":"value3","param4":"value4","param5":"value5","param6":"value6","param7":"value7","param8":"value8"},{"title":"Value 1","price":25,"param1":"value1","param2":"value2","param3":"value3","param4":"value4","param5":"value5","param6":"value6","param7":"value7","param8":"value8"},{"title":"Value 2","price":32,"param1":"value1","param2":"value2","param3":"value3","param4":"value4","param5":"value5","param6":"value6","param7":"value7","param8":"value8"},{"title":"Value 3","price":58,"param1":"value1","param2":"value2","param3":"value3",...

4 – Stream your API
Now that we have a working API let’s stream it using Streamdata.io.
You can use our demo proxy to make a quick test it using following cURL command:

curl "https://proxy.streamdata.io/https://<your-subdomain>.amazonaws.com/<>"

Note: Make sure to keep the https://proxy.streamdata.io/ as a prefix and do not forget to replace <your-subdomain> by the Invoke URL provided by AWS API Gateway.

You should now receive a first snapshot of your content followed by JSON patch updates whenever a change is happening.

id:ebd91a44-19e7-4941-af4d-70bc7eb6de54
event:data
data:[{"title":"Value 0","price":94,"param1":"value1","param2":"value2","param3":"value3","param4":"value4","param5":"value5","param6":"value6","param7":"value7","param8":"value8"},{"title":"Value 1","price":14,"param1":"value1","param2":"value2", ...

id:34b99a85-b94b-4b73-9d04-edcb20382321
event:patch
data:[{"op":"replace","path":"/0/price","value":56},{"op":"replace","path":"/2/price","value":89},{"op":"replace","path":"/3/price","value":50},{"op":"replace","path":"/5/price","value":30},{"op":"replace","path":"/8/price","value":91},{"op":"replace","path":"/9/price","value":55},{"op":"replace","path":"/11/price","value":50},{"op":"replace","path":"/12/price","value":14},{"op":"replace","path":"/13/price","value":43}]

Hope you have enjoyed! If you are not a streamdata.io user yet, you can quickly create an free account here.

Share it :
0000

Give it a try!

Try streaming any JSON REST API within 30 sec
curl -v "https://proxy.streamdata.io/http://mysite.com/myJsonRestService?param1=[]&param2=[]"

2 thoughts on “Stream your AWS API Gateway

  • Amazon Web Services is a great platform and this step by step tutorial will be very helpful! The image examples are a great way to understand the steps which is great for learning the user interface quickly.

Leave a Reply

Your email address will not be published. Required fields are marked *