I'm using AWS Amplify to create a Lambda function, REST API, and Cognito user pool. I want to retrieve the Cognito user who made the request to the endpoint so I can access their user attributes.
I selected the serverless Express template for the function:
app.js
app.post('/do-something', async (req, res) => {
// The user pool ID is available as an environment variable.
// I want to get the user and use their user attributes here.
});
And the client-side configuration sets the Authorization header based on the current user's token:
App.js
Amplify.configure({
API: {
endpoints: [
{
name: "sampleCloudApi",
endpoint: "https://xyz.execute-api.us-east-1.amazonaws.com/Development",
custom_header: async () => {
return { Authorization: `Bearer ${(await Auth.currentSession()).getIdToken().getJwtToken()}` }
}
}
]
}
});
Does the event (req.apiGateway.event
) or context hold user information? Or can I use the Authorization header somehow?
Also, what would it look like to make the Cognito call inside the Lambda function? Will this need to use the Admin API?
Thanks!