Lambda NET 6 & Cognito

0

I am working on NET 6 Lambda. I should use Cognito. As I see the schema is: User app->API Gateway->Cognito-> Lambda Should I somehow process authentication in Lambda or it will be done in Gateway? I receive bearer in request in Lambda ? How can I authorize user : is it User, Admin and what methods he can perform?

1 Answer
1
Accepted Answer

Given that Cognito is your chosen service for authentication, your users will be authenticated before they interact with the API Gateway. This means that you do not need to process authentication in your Lambda function. The bearer token, provided by Cognito, will be forwarded through API Gateway to your Lambda function in the event that you need it. I would recommend you read this AWS documentation section to learn more: Control access to a REST API using Amazon Cognito user pools as authorizer

However, if your Lambda function requires knowledge of the authenticated user, the bearer token can be parsed to extract the user's information, which is typically stored in the token's payload.

For authorizing what actions a user or admin can perform, this is usually managed at the level of Cognito User Pools with User Groups and IAM Policies. A user can belong to a group such as 'User' or 'Admin', each having different IAM policies associated with them, dictating what AWS service APIs they can call.

Remember that the actual task of authorization – that is, determining what an authenticated entity can and cannot do – should be handled through a combination of Cognito User Pools, User Groups, and IAM Policies. Cognito can be utilized for Role-Based Access Control (RBAC), where each role has a set of permissions associated with it.

In conclusion, while Lambda does not handle authentication, it can process user information provided in the form of a bearer token if needed. Authorization and permission management is generally handled by Cognito and IAM, though specific permissions should be properly configured for each role.

profile picture
EXPERT
answered a year ago
profile picture
EXPERT
reviewed a month ago
  • Hi Ivan, can you give me any links on examples used Cognito? Thank you

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions