A very brief introduction to Labmda and API Gateway

Amazon API Gateway is one of the core services of AWS, the API Gateway is a fully managed serverless service from AWS and it allows us to create, publish, and run secure APIs at any scale. Starting from this we will see some points for which we should use API Gateway:
- We can create API endpoints to integrate frontend applications with its backend, using RESTful APIs over HTTPS.
- Being a serverless offering, does not require us to provision any servers.
- It allows us to build APIs that are extremely low cost, highly scalable, secure and easy to monitor as well.
- It's a fully managed service and can handle thousands of concurrent API calls.
- We can use it to create RESTful APIs endpoints that communicate over HTTPS and at the backend.
- We can connect the API to different AWS Services.
- We can easily add authentication or authorization to our APIs as well.
In this example we are going to use Lambda and API Gateway services, both of them from AWS.
first of all, we are going to create a Lambda function.

Open your AWS console and go to Lambda. We are going to create a Lambda function, so click on Create function.

For this exercise we are going to create a Author from scratch.

Inside Basic Information, write the name of your lambda function, select Create a new role from AWS policy templates and assing a Role name.
Finally click on create function.

Now you have a lambda function created with some default code.
If you want to see the default code, click on geologyRocks and scroll down.
The next step is going to API Gateway to create an API.

First go to API Gateway console and create an API. The first steps is to create a REST API, select New API and assing it an API name. Finally click on Create API.
When your API is created you need to:
- Create a Resource (path), with the Actions button, and assing it a Resource name.
- Create a Method (get, post, delete, etc.), with the Actions button.
- Assign the lambda function to our API in the Integration Request section.


This screen corresponds to the step number 3 (Assign the lambda function to our API in the Integration Request section). In Integration type Select Lambda Function to integrate a Lambda to our API and in Lambda Function write the name of the Lambda you created.
Now we are going to test our API, click on TEST (Fig 6). We are going to see a view like this:

Finally click on Actions button (Fig 6) and select Deploy API to deploy our API, assign a stage (prod, test, dev, etc.) and click on Deploy.
You will get the invoke URL, copy this URL in your browser and check if your URL works. Be careful if you see a error message like this {“message”:”Missing Authentication Token”}, you just need to add the resource path (/geologymessage) to your URL



If you want to customize your response you need to go to Integration Response (Fig 6) and modify the Mapping Templates, click on application/json and modify the template. $input.body is the data that comes from the response of AWS Lambda.
I hope this little introduction will help you to know how to create an API method get and recieve a customize response.
I would like to know your doubts or comments, please email me at ca.ortiz.pacheco@gmail.com.
