AWS’s API Gateway is a powerful tool that can be used to create frontend applications for Lambda Functions. This article will show you how to use the API Gateway to create a simple frontend application for your Lambda Functions. First, you need to create an Amazon Web Services account and set up your environment. Next, you need to create a new Lambda Function. The following code example creates a simple function that takes an input of “name” and prints out the name of the user who created the function: function myFunction(name) { return “name” + " created function."; } Next, you need to add the API Gateway as a resource in your Amazon Web Services account. To do this, open the AWS Management Console and click on the Resources tab. In the left-hand pane, click on the Add Resource button and select API Gateway from the list of resources. In the next window, enter a name for your new resource and click on OK. You will now see an error message saying that your resource has not been added yet: This is because you first need to set up some environment variables before adding your new resource: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS . The following code example sets up these environment variables: export AWS_ACCESS_KEY_ID= “your-access-key-id” export AWS_SECRET_ACCESS= “your-secret-access-key” Now that you have set up your environment variables, it’s time to add your new resource: aws ec2 add-resource –name myResource –type aws-api-gateway


API Gateway is a fully managed service for building, testing, and hosting production APIs. Rather than renting an EC2 server and managing your API server yourself, API Gateway can handle it for you and streamline the whole process.

What Is API Gateway?

API Gateway is essentially a reverse proxy, fetching data from other services and returning it in a structured manner. Rather than running it yourself though, the burden of handling the traffic and infrastructure is passed off to AWS, who can get it done for much cheaper.

This basically allows API Gateway to act as a “front door” for a lot of other AWS services. For example, by connecting it to AWS Lambda, you can build a backend of microservices without using any EC2 servers. The Lambda function can be set up for connection.

API Gateway does a great job as a basic frontend for general purpose HTTP APIs, but it’s also very useful for managing the overall structure and schema of REST APIs. When building REST APIs, you’re able to neatly define all of the routes and methods, and connect them up to any AWS service you wish.

API GateWay can also be used to manage WebSocket APIs, which are used for quick real-time communication by opening a direct connection from server to client.

How Much Does API Gateway Cost?

For generic HTTP APIs, API Gateway simply costs $1.00 per million requests, after you exceed the first million that come with the Free Tier.

For REST APIs, the price is higher at $3.50 per million requests. Optionally, you can also choose to enable caching for your REST API, which will improve performance at the cost of an hourly fee based on the size of your cache.

For WebSocket APIs, pricing is a bit different. Because they’re intended for short messages from server to client, you’re only charged $1 per billion requests, 1000 is cheap per request as the other two. However, you’re limited to 128 KB payloads, and you’re also charged $0.25 per million connection minutes. If you consistently have many clients connected to the WebSocket API, you’ll be paying for each of them.

One thing to note, though, is that while there’s no specific charge for data transfer, HTTP APIs are metered in 512 KB increments. For example, a single API request that returned a 1.5 MB response would be billed as three API requests. WebSocket APIs are billed in 32 KB increments. This can easily double your API Gateway costs if your payloads are particularly large.

Of course, if you’re connecting to another AWS service, you’ll have to pay all the costs associated with that services (such as charges for Lambda function invocations) as well as data transfer charges for moving data out of AWS.

Setting Up an HTTP API to Connect to Lambda

While REST APIs offer more organizational tools for managing the API itself, they’re a lot more complicated, and they cost quite a bit more to boot. Instead, we’ll use the basic HTTP APIs, which are easier to create and hook up to Lambda.

Choose to build an “HTTP API” from the creation menu. The first thing you’ll have to configure is your integrations; HTTP APIs support HTTP endpoints and Lambda functions. You can add multiple integrations, which can be useful if you want to have a seperate Lambda function handle each route of your API.

Next, you’ll configure the routes for the API. These can be put on sub-URLs like /users, and will call different integration targets based on the method a client connects with. For example, GET /messages might return a list of messages, but POST /messages might upload a new message.

You’ll probably want a way to distinguish between development and production APIs. You’re able to create multiple environments in the form of “Stages,” which will serve this purpose. By default, the $default environment is automatically updated with any changes and serves as the development stage. You’ll probably want to create a “Production” stage that you can use to push changes from $default to.

After that, your API should be set up and ready for use. Under “Stages,” you’ll find the invocation URL for your API. This is tied to the API deployment stage itself, and will remain static. It should look something like the following:

If you want to use this with a custom domain name, you’ll have to generate an ACM certificate to link API Gateway securely to your domain, and edit your DNS configuration to point to the Gateway itself. If you’re using Route 53, this process is streamlined quite a bit.

Under the “Authorization” tab, you’ll find settings for configuring your API with JWT authentication. This is currently the only method supported with HTTP APIs.