Login in AWS Lambda .Net Core with Cognito

Viewed 134

I used Cognito in my javascript. But I am implementing a Lambda Function that requires logging in

The first approach I did was DynamoDB

if (apiGatewayProxyRequest.Headers.ContainsKey("username") ||
apiGatewayProxyRequest.Headers.ContainsKey("password"))

//check if existing in dynamodb
//if yes continue
//else return unauthorized

But is it possible to use Lambda event in .Net Core with Cognito to determine login

this is what I am planning to use almost the same code as the one I am using for dynamodb but now using cognito

if (apiGatewayProxyRequest.Headers.ContainsKey("username") ||
apiGatewayProxyRequest.Headers.ContainsKey("password"))

//check if existing in Cognito
//if yes continue
//else return unauthorized
1 Answers

If you specifically want to invoke a lambda when a user has logged in, use Cognito triggers to automatically run when an event like that occurs.

If you are trying to secure all your lambda functions, as you are using API Gateway I suggest you setup authorization. This is better as unauthorised users will not be able to invoke the lambda function.

An authorised request will add additional information in the proxy request to help you identify that user which you could then use to query Cognito to retrieve more information.

Related