Last active
March 8, 2023 08:53
-
-
Save dabit3/1f61f6f5b519a09fa977a323ea1c0b16 to your computer and use it in GitHub Desktop.
Accessing Cognito Identity information on the server with Amplify, API Gateway, and Lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In a regular Lambda function | |
const user = event.requestContext.authorizer.claims | |
// In a Serverless Express route | |
const user = req.apiGateway.event.requestContext.authorizer.claims | |
// On client | |
async function callApi() { | |
const user = await Auth.currentAuthenticatedUser() | |
const token = user.signInUserSession.idToken.jwtToken | |
const requestData = { | |
headers: { | |
Authorization: token | |
} | |
} | |
const data = await API.get('testrestapi', '/hello', requestData) | |
console.log("data: ", data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Nader,
how to do this with cloudformation template?
Because with what you mentioned in the tutorial it will be overwritten everytime you redeploy the API with amplify.
Thank you