Skip to content

Instantly share code, notes, and snippets.

@dabit3
Last active March 8, 2023 08:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dabit3/1f61f6f5b519a09fa977a323ea1c0b16 to your computer and use it in GitHub Desktop.
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
// 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)
}
@wordisthebird
Copy link

I watched your video on Youtube! it was fantastic! Would you please have a look at my issue here running this code with react native: aws-amplify/amplify-js#7670 (comment)

@ledgerdevelop
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment