Related Resources

Our Services

You May Also Like

Learn Serverless with few simple step — AWS API Gateway (Part 2)

Krunal Shah

Apr 25, 2018

5 min readLast Updated Sep 14, 2020

Learn Serverless with few simple step AWS API Gateway

What is API Gateway?

API Gateway can be considered a backplane in the cloud to connect AWS services and other public or private websites. It provides consistent RESTful application programming interfaces (APIs) for mobile and web applications to access AWS services.

The following diagram shows API Gateway architecture.

In practical terms, API Gateway lets you create, configure, and host a RESTful API to enable applications to access the AWS Cloud. For example, an application can call an API in API Gateway to upload a user’s annual income and expense data to Amazon Simple Storage Service or Amazon DynamoDB, process the data in AWS Lambda to compute tax owed, and file a tax return via the IRS website.

If you have not checked out our Part 1 of Serverless series. Before proceeding to this blog. Please checkout — Learn Serverless with few simple steps — AWS Lambda (Part 1) .

Create API Gateway

To create new API login into AWS API Gateway Console. Create new API by just entering API name, Description and Endpoint Type.

Access “Hello World” Lambda with API Gateway

After you create API Gateway you will see screen with “/” route. Here you can add resource and method.

Click on the resource and create a resource as “api” or any other name you like as base route in your APIs.

The API is ready now and you can add more resource to get the desired path.

Here you can add “hello” route and bind demo lambda and to get “Hello from Lambda” as response.

For that create another resource “hello” by repeating the above process.

Now it’s time to add method to the resource i.e. in restful api there are various method like GET, PUT, POST and so on.

You can add method by clicking on ACTION button and then Create Method.

For example we select GET method. And bind the “Demo” lambda with it.

Select Integration Type as Lambda Function. Lambda region should be select where you lambda exists. And the you can get the list of Lambda Functions from that region and can select specific function that need to be integrated with the API. Here Demo will be select which was created in previous lambda blog.

Here, you will see the screen where provision is available to configure Method Request, Integration Request, Method Response and Integration Response.

In Method Request, you can added custom authorisation, header parameters, URL parameter and so on. And will be discussed in some other blog.

In Integration Request, you need to integrate request and added “application /json” in request Body Mapping.

Now select Method Request Pass through as default generate template. You can configure this as per requirement. But for now we are using as it is. Click on the save button to save changes.

Again, our case we do not need to add method response and integration response. Therefore, we can directly test it.

After testing you will receive response from lambda.

Access Parameterized Lambda with API Gateway

In previous example, it was simple API to fetch data but what if you need to pass dynamic data or parameter. Here is the solution in our next example.

In our blog, there was a parameter which was passed in event file and lambda was able to access it. We are going to use that same lambda for create this API.

For that create new resource, but here you need to pass as parameter so you need to pass it in {name}.

Integrate Request and add body mapping template as shown in the above examples.

When you go on test screen you will have space to provide particular name which will passed in Lambda and will give personalised greetings.

Deploy API

Now you will be wondering how can you access API from any other place. Yes, for that you need to Deploy API. So access it via Postman or any other place.

It is very simple to Deploy API, click on Action and from that drop down menu select Deploy API, and create new stage variable. After that step your APIs are ready to accessed from any point.

Testing API with Postman

Handling of HTTP methods in API Gateway

Handle responses in API Gateway

Stay tuned for the part three of the blog “Learn Serverless with few simple step”.

Happy coding !!!

· · · ·

Third Rock Techkno is a leading IT services company. We are a top-ranked web, voice and mobile app development company with over 10 years of experience. Client success forms the core of our value system.

We have expertise in the latest technologies including angular, react native, iOs, Android and more. Third Rock Techkno has developed smart, scalable and innovative solutions for clients across a host of industries.

Our team of dedicated developers combine their knowledge and skills to develop and deliver web and mobile apps that boost business and increase output for our clients.

Projects Completed till now.

Discover how we can help your business grow.

"Third Rock Techkno's work integrates complex frameworks and features to offer everything researchers need. They are open-minded and worked smoothly with the academic subject matter."

- Dr Daniel T. Michaels, NINS