Twitter LogoFacebook Logo
API Gateway
Building an API using API Gateway so we can execute the lambda functions through HTTP Requests.
By: King

Hello, in this tutorial, we’ll continue building the Login System using Amazon Cognito, API Gateway, Lambda Function, and the HTTP Requests for Blueprints plugin. 

In the last tutorial, we created the lambda for signing in.

Now, we’ll build our API using API Gateway so we can execute the lambda functions through HTTP Requests. 

Creating the API

Login to your AWS Console and search for API Gateway in the search bar and select it in the menu.

Image from Codeible.com

Look for the REST API section and click Build.

Image from Codeible.com

Select New API


Give it a name like LoginAPI

Click Create API to create it.

Image from Codeible.com

In the Actions dropdown menu, click on Create a new Resource

Image from Codeible.com

Give the resource a name like, signup and use signup for the path.

Click on Create Resource to complete the process. 

This will allow us to create our API endpoints under the auth resource path once we define them, which you’ll see what I mean later.

Image from Codeible.com

Click on the resource that was created. 


Then click on the Actions dropdown and create a new Method

Image from Codeible.com

Select POST in the dropdown under the resource and click the Check icon. 

Image from Codeible.com

On the right side, make sure the Lambda Function is selected for the Integration type and the Lambda Region is the region for your Lambda.

For the Lambda Function, type in the name of the lambda that is used for creating accounts. 


Click “Save” to create the method.

Image from Codeible.com

For the Permission alert, select “OK.” to automatically apply the correct permissions to our API to call the lambda.

Now we have our first endpoint for our API endpoint.

To test this, click on the Actions dropdown and deploy the API.

Image from Codeible.com

Select [New Stage] for the Deployment stage. 


Then give the Stage a name like api

Click “Deploy” to complete the process.

Image from Codeible.com

Testing

Now we can use the Invoke URL provided to us to test.


Open your Unreal Engine project and then enable the HTTP Requests for Blueprints plugin. 

Image from Codeible.com

Open the level blueprint and call Event Begin Play if you do not have it. 


After, use the Make a HTTP Request node from the plugin.

Select POST for the method since the endpoint we created is a POST request. 


Paste the Invoke URL in the URL pin. 

Image from Codeible.com

If we take a look at the Resources tab, the endpoint we want to use is /signup. So, in the blueprint node, we need to add it at the end of the URL.

Image from Codeible.com
Image from Codeible.com

For the params, create an empty map. For the headers, set the Content-Type to application/json to indicate that we want to send in a JSON object with the request.  

For the Body, we need to pass in a JSON object with a username and password value. To do that, call the Append node for strings.

Image from Codeible.com

For the first slot, put the open curly bracket. For the 2nd slot, do open quote, username, close quote, colon, open quote, a valid email you can use to test, close quotes, then a comma.


Click on Add pin to create a new slot and do the same for the password. 

Remove the comma for the password. And add a new pin for the closing curly bracket to end the JSON object.

Set it as the Body of the request, then add the On Complete callback. 

Image from Codeible.com

Click and hold on it, then drag on an empty spot. Select Add Event, then Add Custom Event.

Image from Codeible.com

Compile, save, and launch the app. 


If you are using the same email from earlier, make sure to delete it from the pool so you can use it to create the account again.

If we refresh the user pool, you should see the user.

Image from Codeible.com

Creating the Confirmation Endpoint

Now, let’s finish creating the API. 


Go back to API Gateway.

Click on the root and open the Actions dropdown to create a new Resource. Name it confirm, and leave the path the same as the name.

Now click on Confirm Resource and create a new method. 

Select POST from the dropdown menu under Confirm Resource and click on the check icon. 

This time, we want to use the ConfirmAccount lambda.

Click “Save” and add the permission

Creating the SignIn Endpoint

For the last endpoint, create a resource call signin. Then create a POST method under it. 

This time, we want to use the lambda for signing in.

Deploy

That’s all the endpoint we’ll need. Now we just need to deploy it. 


In the Actions dropdown, click on Deploy API. Then select the stage that was create earlier and click “Deploy.”

That’s all for this tutorial.

Image from Codeible.com

Sign In