Created
August 5, 2022 14:01
-
-
Save daaru00/14069f2a09fbd3ff84c86de731980927 to your computer and use it in GitHub Desktop.
X-Ray integration with Lambda
This file contains hidden or 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
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