Search code examples
amazon-web-servicesaws-lambdajwtamazon-cognito

Authentication with Lambda and AWS Cognito


After days of trial and error, I finally managed to get signin/signup working in VueJS with AWS Cognito. I have an idToken and accessToken and would like to pass that on to my Lambda function.

I read something about the API Gateway which has options for authentication, but there's no simple explanation how this all works together.

Any suggestions or hints how to move forward?

  • Use aws-sdk within the function and somehow get the username/userid?
  • Use the API Gateway to pass on the user before the function is invoked?

Solution

  • Amazon Cognito User Pool makes it easy for developers to add sign-up and sign-in functionality to web and mobile applications. It serves as your own identity provider to maintain a user directory. It supports user registration and sign-in, as well as provisioning identity tokens for signed-in users as per doc

    Now you have two options to configure Cognito pool with API getway

    1) Use cognito authorizer : If you need to authantcate and authorize using Oauth.

    2) Lambda custom authorizer : If you need custom IAM roles and Federated Identities or own logic.

    Long story short here is you can find further detail:

    Suggestions or hints

    Use aws-sdk within the function and somehow get the username/userid?

    You can use lambda authorizer and use sdk to get info if need custom logic based on user

    Use the API Gateway to pass on the user before the function is invoked?

    Not clear ur question but as per my assumption - Cognito authorizer on api getway automatically takecare user id validation