Have you ever wondered what Amazon API Gateway is, what it’s best for, and what its limitations are? Don’t worry, we’ve got you covered.
Amazon Web Services, better known as AWS, offers products in computing, storage, networking and content delivery. It has two types of tools for creating and publishing APIs – AWS API Gateway and AWS Lambda – and we’ll look at how they fit together in this article. We’ll also take a quick tour of the interface to get started with an API right away.
What is AWS API Gateway?
What is AWS Lambda?
What is an API?
XML and JSON are the most popular markup languages for exposing content.
How does AWS API Gateway work?
After creating API flows, you can sketch out the API structure using the service’s graphical user interface.
Our recommendation is that you create your API structure using code instead of using the user interface, such as the built-in API Gateway event available in the Serverless Framework.
API Gateway’s role in Serverless
With the Serverless framework, you can use API Gateway to setup your Lambda functions. For instance, you can perform a GET request and retrieve all related data. This data is then available to the Lambda function. API Gateway is the trigger that causes Lambda functions to run.
Benefits of AWS API Gateway?
API Gateways provide tier-based pricing models for API requests. API requests cost as little as $1.51 per million requests, and you can decrease costs by decreasing the number of API requests.
Caching:
API Gateway can cache endpoint responses, which reduces request latency by caching the endpoint’s responses. Furthermore, it determines the price of the service.
Throttling:
It is also possible to protect your API Gateway from security risks. If you wish to prevent API calls from flooding your API Gateway, you can configure a throttle service that limits requests to prevent attacks.
Scalability:
It is not necessary to have EC2 services or Autoscaling groups responding to API requests. API Gateways scale automatically.
Flexibility:
Implementing the API Gateway does not require an AWS EC2 instance or the Gateway software. API Gateway can be implemented through the AWS Management Console in just a few minutes.
Lets get started!
Task 1: Create Lambda Function
- Login to Amazon Management Console and open Lambda either from Services or from the search.
- Click on Create Function in the Function Dashboard.
- Select Use a Blueprint to create a function and then search and select hello-world-python. Click on configure.
- Give your function unique name and keep all other setting settings as default. Click Create Function.
You may remove prints statements from the code.
print(“value1 = ” + event[‘key1’])
print(“value2 = ” + event[‘key2’])
print(“value3 = ” + event[‘key3’])
And make return statement as:-
return”hello” # Echo back the first key value
You have successfully created a Lambda function. Now we will create an API Gateway.
Task 2: Create API Gateway
- Search and open API Gateway. Click on Create API.
- Choose an API type as Rest API and click on Build.
- Give your API a name and description. Click on Create API.
- In API Dashboard, Click on actions and then Create Method.
- 5.From dropdown menu select GET and then click on tick mark icon.
- In Lambda Function, add the name of the function you just created and click on Save and give permissions to invoke the lambda function.
- Now you can test the integration of Lambda to API Gateway. Click on Test and you will get the output as shown below.
- Now you need to deploy the API. Click on Actions and then on Deploy API. A popup opens, select the stage as New Stage and give it a name. Click on Deploy.
You have finally deployed your first API Gateway. Now you can copy the url and run it in new browser to see the output.
No comment yet, add your voice below!