This Hello sekitaka. Learn how to pass a Cognito Identity Id from API Gateway to Lambda.
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.
Method request of any method of API → Set authentication to "AWS_IAM".
Integration request → Specify the body mapping template as follows.
{
"cognito_id": "$context.identity.cognitoIdentityId"
}
You can pass a Cognito Id to Lambda with a property called cognito_id by specifying " $ context.identity.cognitoIdentityId "
.
You can use it in Lambda as follows.
def lambda_handler(event, context):
cognito_id = event.get('cognito_id')
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