Skip to content

Instantly share code, notes, and snippets.

@daaru00
Created August 5, 2022 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daaru00/14069f2a09fbd3ff84c86de731980927 to your computer and use it in GitHub Desktop.
Save daaru00/14069f2a09fbd3ff84c86de731980927 to your computer and use it in GitHub Desktop.
X-Ray integration with Lambda
const AWSXRay = require('aws-xray-sdk')
AWSXRay.setLogger(console)
/**
* Lambda handler
*/
exports.handler = async (event) => {
console.log(JSON.stringify(event))
const user = event.requestContext.authorizer.claims
const segment = AWSXRay.getSegment().addNewSubsegment('user')
segment.addAttribute('user', user)
segment.addAnnotation('user_name', user.name)
segment.addAnnotation('user_email', user.email)
segment.addMetadata('user', user.email)
//segment.addError('User does not exist')
segment.close()
return {
statusCode: 200,
body: JSON.stringify({
name: user.name,
email: user.email,
}),
headers: {
'access-control-allow-origin': event.headers.origin,
'access-control-allow-headers': '*',
'access-control-allow-methods': 'GET'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment