Sharing what we learn—it’s our way of giving back.

Developing and managing custom applications, we encounter a variety of needs,
challenges, and perspectives. It’s our hope you find these articles helpful in
guiding your own work and avoiding a few pitfalls along the way.

AWS API Gateway

AWS API Gateway

AWS API Gateway helps us to expose API to end users by integrating with different AWS services or other HTTP services. Using API Gateway we can expose, monitor and secure the APIs. It doesn't restrict the number of requests concurrently. It can be scaled at any level. We can expose the RESTFul API so that end users (like web applications, mobile apps) can invoke the API.

API Gateway pricing is based on the usage of the APIs. We don't need to pay any upfront fee to create API. It is being charged based on the API calls received and data that is being transferred out. AWS API Gateway also provides data caching mechanism where it charges more based on the cached data size.

In this article we will demonstrate how we can create API Gateway and integrate with Lambda Function. This becomes part of the serverless architecture where we don't have any server to deploy API or run our business logic on server.

For this article we expect Lambda function is already created as demonstrated in article.

Create and Configure API Gateway

  1. Sign-in to AWS Console
  2. Click on API Gateway under Application Services or go to https://console.aws.amazon.com/apigateway/home
  3. Click Create API

    Here we have multiple options to create API as:
    • New API: Choose this option when you want to create API by your own step-by-step
    • Clone from existing API: Choose this option when you want to create API by cloning from existing API
    • Import from Swagger: Choose this option when you have Swagger API definition and that API definition can be imported here to create API
    • Example API: Choose this option when you want to create API using example API
    For our example, we will choose New API option and provide the friendly name and description for our API. Then click Create API
  4. Create Resource
    Here we will create greet resource that acts as a endpoint suffix for our API.
    Under Resources navigation pane, click Actions > Create Resource

    You will be redirected to Add Child Resource screen

    Provide the following details:
    • Configure as proxy resource: We can configure the resource to act as a proxy resource
    • Resource Name: Friendly resource name
    • Resource Path: Endpoint path suffix for the resource to be identified
    • Enable API Gateway CORS: This parameter needs to be enabled when we want our API to be consumed from domains other than our API's domain.
    Once inputs are filled in, click Create Resource
  5. Create Method
    Here we will create Post HTTP method under greet resource. Select the /greet resource and click Actions > Create Method

    You will be asked to choose HTTP method you want to create as:

    Choose POST and click checked symbol
  6. Integrate Lambda Function
    Here we will integrate lambda function when our greet's POST method is being called. Provide the following details:
    • Integration Type: API gateway offer's four types of integration
      1. Lambda Function: Invoke lambda function when the API Gateway resource method gets invoked
      2. HTTP: Invoke existing HTTP endpoint
      3. Mock: We can return the mock response to the service call
      4. AWS Service: We can integrate various AWS services
      For our example, we will choose integration type as Lambda Function
    • Use Lambda Proxy integration: Select whether lambda function acts as proxy integration. We will deselect this property for our example.
    • Lambda Region: Select the region where your Lambda Function resides. We will select us-east-1 as we created lambda function in this region.
    • Lambda Function: Choose your lambda function
    Once inputs are filled, click Save. You will be prompted for adding permissions to selected lambda function.

    Click OK
  7. Deploy API
    Under this step, we will deploy our API to specific stage. Stage defines the environment of your API - Development, Test, Production, etc.
    Click Actions > Deploy API.

    You will be prompted for deploy API inputs:
    • Deployment stage: Choose [New Stage] option
    • Stage name: Your environment name
    • Stage description: Description for stage
    • Deployment description: Description of deployment being done to specific stage. This may include what changes made to API.

    Click Deploy. You will be redirected to Stages where you can see your stage is being created and Endpoint for your resource is created.
  8. Testing
    Our API is ready to be consumed. Copy the Invoke URL and test using any Rest Client tool of your choice. Provide the details as:
    • URL: https://hlrpmcn911.execute-api.us-east-1.amazonaws.com/Development/greet
    • Method: POST
    • Body: "Addo"

    You can see the output that is being returned from the lambda function via API Gateway.

Conclusion

In this article we have seen how to configure API Gateway and integrate lambda function using the AWS Management Console.

Contact Us

Have a question about us or our service? Feel free to
send us a note anytime, or call us during business
hours, Monday - Friday, 9am to 5pm EST.

350 Massachusetts Ave,
Suite 300
Indianapolis, IN 46204

(877) 630-2336