Created
June 25, 2017 18:48
-
-
Save theburningmonk/0fb966c06b3785bc5289a895a83f027c to your computer and use it in GitHub Desktop.
service-a
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
| // ... omitted for brevity | |
| module.exports.handler = co.wrap(function* (event, context, callback) { | |
| console.log(JSON.stringify(event)); | |
| console.log(JSON.stringify(context)); | |
| global.hostname = event.headers.Host; | |
| global.accountId = event.requestContext.accountId; | |
| global.requestId = event.requestContext.requestId; | |
| let segment = AWSXRay.getSegment(); | |
| console.log(JSON.stringify(segment)); | |
| let n = Math.random() * 3; | |
| segment.addMetadata('random', `${n}`); // this doesn't work | |
| segment.addAnnotation('path', event.path); // this doesn't work | |
| if (n <= 1) { | |
| yield publishSNS(segment); | |
| yield accessS3(segment); | |
| yield accessDynamoDB(segment); | |
| yield invokeLambda(segment); | |
| let message = yield callServiceB(segment, n); | |
| const response = { | |
| statusCode: 200, | |
| body: JSON.stringify({ | |
| message: `service-b says ${message}` | |
| }), | |
| }; | |
| callback(null, response); | |
| } else if (n <= 2) { | |
| console.log("service-a is going to call the timeout endpoint"); | |
| yield utils.request('GET', hostname, '/dev/demo/timeout'); | |
| throw new Error("timed out"); | |
| } else { | |
| console.log("service-a is going to call the error endpoint"); | |
| yield utils.request('GET', hostname, '/dev/demo/error'); | |
| throw new Error("boom"); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment