Creating the lambda
Login to your AWS Console and search for Lambda in the search bar.
Create a new function. Give the lambda a name like SignIn. Then set the Runtime to Node.js and click “Create function” to complete the process.
Now open the AWS SDK documentation for Cognito Identity Provider. Search for InitiateAuth and hit enter a couple of times.
Copy the import statement and paste it inside the Lambda function.
Now go back to the documentation, and copy the rest.
Paste the whole thing in the handler function.
const client = new CognitoIdentityProviderClient({region: "us-east-1"});
Now delete everything in the input except for the required ones.
For the AuthFlow, use USER_PASSWORD_AUTH, since that is what we defined in the Cognito User pool.
AuthFlow: "USER_PASSWORD_AUTH"
The ClientId is for a Cognito User pool app client id.
Save the code and deploy it.
Testing
To test this, click on the arrow next to the Test button and select Configure test event.
Give the event a name like LoginTest.
If you get a 200 response with the access and id token, you successfully logged in.
That’s all for this tutorial. In the next tutorial, we’ll use API Gateway and create our own API to execute these lambdas in Unreal Engine.