Pass Cognito Id to Lambda via API Gateway

This Hello sekitaka. Learn how to pass a Cognito Identity Id from API Gateway to Lambda.

situation

This method can be used in the following situations.

Suppose you're using Cognito on your mobile app and you have API Gateway authentication set to IAM authentication. In other words, only the user who has the correct Cognito Identity Id (hereinafter referred to as Cognito Id) can execute the API. In this state, you may want to use Cognito Id with Lambda, the backend of the API. For example, if you want to create data for each user in DynamoDB with Cognito Id as the primary key, or create a profile image file in S3.

procedure

You can pass a Cognito Id to Lambda with a property called cognito_id by specifying " $ context.identity.cognitoIdentityId ".

Summary

What did you think. This time, I showed you how to pass Cognito Identity Id to Lambda via API Gateway. I think it is one of the necessary knowledge when creating a serverless mobile application using AWS.

Recommended Posts

Pass Cognito Id to Lambda via API Gateway
A note that connects to Lambda via AWS API Gateway (HTTP API) to process POST data
[AWS] Create API with API Gateway + Lambda
Send images taken with ESP32-WROOM-32 to AWS (API Gateway → Lambda → S3)
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
Easy REST API with API Gateway / Lambda / DynamoDB
[AWS SAM] Create API with DynamoDB + Lambda + API Gateway
LINE BOT with Python + AWS Lambda + API Gateway
[AWS] Try tracing API Gateway + Lambda with X-Ray
Amazon API Gateway and AWS Lambda Python version