aws-lambda-helper
Advanced tools
Comparing version 2.7.0 to 2.8.0
@@ -1,1 +0,1 @@ | ||
{"/home/jimmy/repo/aws-lambda-helper/lib/index.js":{"path":"/home/jimmy/repo/aws-lambda-helper/lib/index.js","s":{"1":1,"2":1,"3":1,"4":17,"5":17,"6":17,"7":17,"8":17,"9":16,"10":16,"11":1,"12":19,"13":1,"14":18,"15":18,"16":3,"17":3,"18":3,"19":3,"20":3,"21":15,"22":13,"23":13,"24":13,"25":13,"26":2,"27":1,"28":2,"29":1,"30":3,"31":1,"32":2,"33":1,"34":2,"35":2,"36":2,"37":1,"38":3,"39":1,"40":3,"41":1,"42":2,"43":1,"44":2,"45":2,"46":2,"47":1,"48":3,"49":1,"50":3,"51":1,"52":2,"53":2,"54":2,"55":1,"56":3,"57":1,"58":1},"b":{"1":[1,18],"2":[3,15],"3":[13,2],"4":[1,2],"5":[3,2],"6":[1,1],"7":[2,2],"8":[2,2],"9":[2,2],"10":[3,1],"11":[1,2],"12":[3,2],"13":[1,1],"14":[2,2],"15":[2,2],"16":[2,2],"17":[3,1],"18":[1,2],"19":[3,2],"20":[3,1]},"f":{"1":17,"2":19,"3":2,"4":3,"5":3,"6":3,"7":3,"8":3,"9":3},"fnMap":{"1":{"name":"init","line":20,"loc":{"start":{"line":20,"column":0},"end":{"line":20,"column":24}}},"2":{"name":"(anonymous_2)","line":30,"loc":{"start":{"line":30,"column":37},"end":{"line":30,"column":67}}},"3":{"name":"(anonymous_3)","line":53,"loc":{"start":{"line":53,"column":27},"end":{"line":53,"column":46}}},"4":{"name":"(anonymous_4)","line":62,"loc":{"start":{"line":62,"column":26},"end":{"line":62,"column":48}}},"5":{"name":"(anonymous_5)","line":85,"loc":{"start":{"line":85,"column":30},"end":{"line":85,"column":42}}},"6":{"name":"(anonymous_6)","line":95,"loc":{"start":{"line":95,"column":24},"end":{"line":95,"column":46}}},"7":{"name":"(anonymous_7)","line":118,"loc":{"start":{"line":118,"column":27},"end":{"line":118,"column":39}}},"8":{"name":"(anonymous_8)","line":127,"loc":{"start":{"line":127,"column":29},"end":{"line":127,"column":51}}},"9":{"name":"(anonymous_9)","line":142,"loc":{"start":{"line":142,"column":32},"end":{"line":142,"column":44}}}},"statementMap":{"1":{"start":{"line":3,"column":0},"end":{"line":3,"column":29}},"2":{"start":{"line":4,"column":0},"end":{"line":17,"column":2}},"3":{"start":{"line":20,"column":0},"end":{"line":28,"column":1}},"4":{"start":{"line":21,"column":2},"end":{"line":21,"column":31}},"5":{"start":{"line":22,"column":2},"end":{"line":22,"column":27}},"6":{"start":{"line":23,"column":2},"end":{"line":23,"column":24}},"7":{"start":{"line":24,"column":2},"end":{"line":24,"column":29}},"8":{"start":{"line":25,"column":2},"end":{"line":25,"column":65}},"9":{"start":{"line":26,"column":2},"end":{"line":26,"column":50}},"10":{"start":{"line":27,"column":2},"end":{"line":27,"column":19}},"11":{"start":{"line":30,"column":0},"end":{"line":49,"column":2}},"12":{"start":{"line":31,"column":2},"end":{"line":31,"column":109}},"13":{"start":{"line":31,"column":27},"end":{"line":31,"column":109}},"14":{"start":{"line":32,"column":2},"end":{"line":32,"column":62}},"15":{"start":{"line":34,"column":2},"end":{"line":40,"column":3}},"16":{"start":{"line":35,"column":4},"end":{"line":35,"column":50}},"17":{"start":{"line":36,"column":4},"end":{"line":36,"column":51}},"18":{"start":{"line":37,"column":4},"end":{"line":37,"column":34}},"19":{"start":{"line":38,"column":4},"end":{"line":38,"column":25}},"20":{"start":{"line":39,"column":4},"end":{"line":39,"column":21}},"21":{"start":{"line":42,"column":2},"end":{"line":47,"column":3}},"22":{"start":{"line":43,"column":4},"end":{"line":43,"column":50}},"23":{"start":{"line":44,"column":4},"end":{"line":44,"column":51}},"24":{"start":{"line":45,"column":4},"end":{"line":45,"column":67}},"25":{"start":{"line":46,"column":4},"end":{"line":46,"column":21}},"26":{"start":{"line":48,"column":2},"end":{"line":48,"column":81}},"27":{"start":{"line":53,"column":0},"end":{"line":55,"column":2}},"28":{"start":{"line":54,"column":2},"end":{"line":54,"column":27}},"29":{"start":{"line":62,"column":0},"end":{"line":83,"column":2}},"30":{"start":{"line":63,"column":2},"end":{"line":65,"column":3}},"31":{"start":{"line":64,"column":4},"end":{"line":64,"column":55}},"32":{"start":{"line":68,"column":2},"end":{"line":70,"column":3}},"33":{"start":{"line":69,"column":4},"end":{"line":69,"column":72}},"34":{"start":{"line":72,"column":2},"end":{"line":72,"column":32}},"35":{"start":{"line":74,"column":2},"end":{"line":80,"column":4}},"36":{"start":{"line":82,"column":2},"end":{"line":82,"column":41}},"37":{"start":{"line":85,"column":0},"end":{"line":87,"column":2}},"38":{"start":{"line":86,"column":2},"end":{"line":86,"column":71}},"39":{"start":{"line":95,"column":0},"end":{"line":116,"column":2}},"40":{"start":{"line":96,"column":2},"end":{"line":98,"column":3}},"41":{"start":{"line":97,"column":4},"end":{"line":97,"column":51}},"42":{"start":{"line":101,"column":2},"end":{"line":103,"column":3}},"43":{"start":{"line":102,"column":4},"end":{"line":102,"column":128}},"44":{"start":{"line":105,"column":2},"end":{"line":105,"column":29}},"45":{"start":{"line":107,"column":2},"end":{"line":113,"column":4}},"46":{"start":{"line":115,"column":2},"end":{"line":115,"column":39}},"47":{"start":{"line":118,"column":0},"end":{"line":120,"column":2}},"48":{"start":{"line":119,"column":2},"end":{"line":119,"column":62}},"49":{"start":{"line":127,"column":0},"end":{"line":140,"column":2}},"50":{"start":{"line":128,"column":2},"end":{"line":130,"column":3}},"51":{"start":{"line":129,"column":4},"end":{"line":129,"column":52}},"52":{"start":{"line":132,"column":2},"end":{"line":132,"column":34}},"53":{"start":{"line":134,"column":2},"end":{"line":137,"column":4}},"54":{"start":{"line":139,"column":2},"end":{"line":139,"column":44}},"55":{"start":{"line":142,"column":0},"end":{"line":144,"column":2}},"56":{"start":{"line":143,"column":2},"end":{"line":143,"column":77}},"57":{"start":{"line":146,"column":0},"end":{"line":146,"column":27}},"58":{"start":{"line":147,"column":0},"end":{"line":147,"column":57}}},"branchMap":{"1":{"line":31,"type":"if","locations":[{"start":{"line":31,"column":2},"end":{"line":31,"column":2}},{"start":{"line":31,"column":2},"end":{"line":31,"column":2}}]},"2":{"line":34,"type":"if","locations":[{"start":{"line":34,"column":2},"end":{"line":34,"column":2}},{"start":{"line":34,"column":2},"end":{"line":34,"column":2}}]},"3":{"line":42,"type":"if","locations":[{"start":{"line":42,"column":2},"end":{"line":42,"column":2}},{"start":{"line":42,"column":2},"end":{"line":42,"column":2}}]},"4":{"line":63,"type":"if","locations":[{"start":{"line":63,"column":2},"end":{"line":63,"column":2}},{"start":{"line":63,"column":2},"end":{"line":63,"column":2}}]},"5":{"line":63,"type":"binary-expr","locations":[{"start":{"line":63,"column":6},"end":{"line":63,"column":13}},{"start":{"line":63,"column":17},"end":{"line":63,"column":37}}]},"6":{"line":68,"type":"if","locations":[{"start":{"line":68,"column":2},"end":{"line":68,"column":2}},{"start":{"line":68,"column":2},"end":{"line":68,"column":2}}]},"7":{"line":76,"type":"binary-expr","locations":[{"start":{"line":76,"column":20},"end":{"line":76,"column":41}},{"start":{"line":76,"column":45},"end":{"line":76,"column":62}}]},"8":{"line":78,"type":"binary-expr","locations":[{"start":{"line":78,"column":15},"end":{"line":78,"column":31}},{"start":{"line":78,"column":35},"end":{"line":78,"column":52}}]},"9":{"line":79,"type":"binary-expr","locations":[{"start":{"line":79,"column":13},"end":{"line":79,"column":27}},{"start":{"line":79,"column":31},"end":{"line":79,"column":37}}]},"10":{"line":86,"type":"binary-expr","locations":[{"start":{"line":86,"column":22},"end":{"line":86,"column":39}},{"start":{"line":86,"column":43},"end":{"line":86,"column":70}}]},"11":{"line":96,"type":"if","locations":[{"start":{"line":96,"column":2},"end":{"line":96,"column":2}},{"start":{"line":96,"column":2},"end":{"line":96,"column":2}}]},"12":{"line":96,"type":"binary-expr","locations":[{"start":{"line":96,"column":6},"end":{"line":96,"column":13}},{"start":{"line":96,"column":17},"end":{"line":96,"column":33}}]},"13":{"line":101,"type":"if","locations":[{"start":{"line":101,"column":2},"end":{"line":101,"column":2}},{"start":{"line":101,"column":2},"end":{"line":101,"column":2}}]},"14":{"line":109,"type":"binary-expr","locations":[{"start":{"line":109,"column":22},"end":{"line":109,"column":45}},{"start":{"line":109,"column":49},"end":{"line":109,"column":55}}]},"15":{"line":110,"type":"binary-expr","locations":[{"start":{"line":110,"column":13},"end":{"line":110,"column":27}},{"start":{"line":110,"column":31},"end":{"line":110,"column":33}}]},"16":{"line":111,"type":"binary-expr","locations":[{"start":{"line":111,"column":15},"end":{"line":111,"column":31}},{"start":{"line":111,"column":35},"end":{"line":111,"column":50}}]},"17":{"line":119,"type":"binary-expr","locations":[{"start":{"line":119,"column":19},"end":{"line":119,"column":33}},{"start":{"line":119,"column":37},"end":{"line":119,"column":61}}]},"18":{"line":128,"type":"if","locations":[{"start":{"line":128,"column":2},"end":{"line":128,"column":2}},{"start":{"line":128,"column":2},"end":{"line":128,"column":2}}]},"19":{"line":128,"type":"binary-expr","locations":[{"start":{"line":128,"column":6},"end":{"line":128,"column":13}},{"start":{"line":128,"column":17},"end":{"line":128,"column":34}}]},"20":{"line":143,"type":"binary-expr","locations":[{"start":{"line":143,"column":24},"end":{"line":143,"column":43}},{"start":{"line":143,"column":47},"end":{"line":143,"column":76}}]}}}} | ||
{"/Users/Admin/work/aws-lambda-helper/lib/index.js":{"path":"/Users/Admin/work/aws-lambda-helper/lib/index.js","s":{"1":1,"2":1,"3":5,"4":5,"5":2,"6":2,"7":2,"8":2,"9":3,"10":2,"11":2,"12":2,"13":2,"14":1,"15":1,"16":3,"17":3,"18":3,"19":3,"20":3,"21":1,"22":3,"23":1,"24":2,"25":1,"26":1,"27":1,"28":1,"29":2,"30":1,"31":1,"32":1,"33":1,"34":1,"35":1,"36":1,"37":1},"b":{"1":[2,3],"2":[2,1],"3":[3,1],"4":[1,2],"5":[3,3],"6":[2,2],"7":[1,1],"8":[2,1],"9":[1,1],"10":[1,1],"11":[1,1]},"f":{"1":5,"2":3,"3":3,"4":2},"fnMap":{"1":{"name":"extractParams","line":5,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":44}}},"2":{"name":"AwsHelper","line":28,"loc":{"start":{"line":28,"column":0},"end":{"line":28,"column":42}}},"3":{"name":"getEnvironment","line":36,"loc":{"start":{"line":36,"column":0},"end":{"line":36,"column":34}}},"4":{"name":"(anonymous_4)","line":48,"loc":{"start":{"line":48,"column":16},"end":{"line":48,"column":38}}}},"statementMap":{"1":{"start":{"line":3,"column":0},"end":{"line":3,"column":11}},"2":{"start":{"line":5,"column":0},"end":{"line":25,"column":1}},"3":{"start":{"line":7,"column":2},"end":{"line":7,"column":62}},"4":{"start":{"line":10,"column":2},"end":{"line":15,"column":3}},"5":{"start":{"line":11,"column":4},"end":{"line":11,"column":42}},"6":{"start":{"line":12,"column":4},"end":{"line":12,"column":43}},"7":{"start":{"line":13,"column":4},"end":{"line":13,"column":26}},"8":{"start":{"line":14,"column":4},"end":{"line":14,"column":13}},"9":{"start":{"line":17,"column":2},"end":{"line":22,"column":3}},"10":{"start":{"line":18,"column":4},"end":{"line":18,"column":42}},"11":{"start":{"line":19,"column":4},"end":{"line":19,"column":43}},"12":{"start":{"line":20,"column":4},"end":{"line":20,"column":51}},"13":{"start":{"line":21,"column":4},"end":{"line":21,"column":13}},"14":{"start":{"line":24,"column":2},"end":{"line":24,"column":81}},"15":{"start":{"line":28,"column":0},"end":{"line":34,"column":1}},"16":{"start":{"line":29,"column":2},"end":{"line":29,"column":15}},"17":{"start":{"line":30,"column":2},"end":{"line":30,"column":23}},"18":{"start":{"line":31,"column":2},"end":{"line":31,"column":27}},"19":{"start":{"line":32,"column":2},"end":{"line":32,"column":44}},"20":{"start":{"line":33,"column":2},"end":{"line":33,"column":11}},"21":{"start":{"line":36,"column":0},"end":{"line":42,"column":1}},"22":{"start":{"line":37,"column":2},"end":{"line":39,"column":3}},"23":{"start":{"line":38,"column":4},"end":{"line":38,"column":16}},"24":{"start":{"line":40,"column":2},"end":{"line":40,"column":67}},"25":{"start":{"line":41,"column":2},"end":{"line":41,"column":13}},"26":{"start":{"line":44,"column":0},"end":{"line":44,"column":29}},"27":{"start":{"line":46,"column":0},"end":{"line":46,"column":16}},"28":{"start":{"line":48,"column":0},"end":{"line":62,"column":2}},"29":{"start":{"line":49,"column":2},"end":{"line":51,"column":3}},"30":{"start":{"line":50,"column":4},"end":{"line":50,"column":55}},"31":{"start":{"line":52,"column":2},"end":{"line":52,"column":31}},"32":{"start":{"line":53,"column":2},"end":{"line":53,"column":32}},"33":{"start":{"line":54,"column":2},"end":{"line":60,"column":4}},"34":{"start":{"line":61,"column":2},"end":{"line":61,"column":30}},"35":{"start":{"line":63,"column":0},"end":{"line":63,"column":27}},"36":{"start":{"line":64,"column":0},"end":{"line":64,"column":31}},"37":{"start":{"line":65,"column":0},"end":{"line":65,"column":47}}},"branchMap":{"1":{"line":10,"type":"if","locations":[{"start":{"line":10,"column":2},"end":{"line":10,"column":2}},{"start":{"line":10,"column":2},"end":{"line":10,"column":2}}]},"2":{"line":17,"type":"if","locations":[{"start":{"line":17,"column":2},"end":{"line":17,"column":2}},{"start":{"line":17,"column":2},"end":{"line":17,"column":2}}]},"3":{"line":31,"type":"binary-expr","locations":[{"start":{"line":31,"column":14},"end":{"line":31,"column":20}},{"start":{"line":31,"column":24},"end":{"line":31,"column":26}}]},"4":{"line":37,"type":"if","locations":[{"start":{"line":37,"column":2},"end":{"line":37,"column":2}},{"start":{"line":37,"column":2},"end":{"line":37,"column":2}}]},"5":{"line":37,"type":"binary-expr","locations":[{"start":{"line":37,"column":6},"end":{"line":37,"column":14}},{"start":{"line":37,"column":18},"end":{"line":37,"column":45}}]},"6":{"line":40,"type":"binary-expr","locations":[{"start":{"line":40,"column":12},"end":{"line":40,"column":17}},{"start":{"line":40,"column":21},"end":{"line":40,"column":66}}]},"7":{"line":49,"type":"if","locations":[{"start":{"line":49,"column":2},"end":{"line":49,"column":2}},{"start":{"line":49,"column":2},"end":{"line":49,"column":2}}]},"8":{"line":49,"type":"binary-expr","locations":[{"start":{"line":49,"column":6},"end":{"line":49,"column":13}},{"start":{"line":49,"column":17},"end":{"line":49,"column":37}}]},"9":{"line":56,"type":"binary-expr","locations":[{"start":{"line":56,"column":20},"end":{"line":56,"column":50}},{"start":{"line":56,"column":54},"end":{"line":56,"column":71}}]},"10":{"line":58,"type":"binary-expr","locations":[{"start":{"line":58,"column":15},"end":{"line":58,"column":31}},{"start":{"line":58,"column":35},"end":{"line":58,"column":44}}]},"11":{"line":59,"type":"binary-expr","locations":[{"start":{"line":59,"column":13},"end":{"line":59,"column":43}},{"start":{"line":59,"column":47},"end":{"line":59,"column":53}}]}}}} |
@@ -18,3 +18,4 @@ 'use strict'; | ||
DynamoDB: {}, | ||
init: init | ||
init: init, | ||
log: {} | ||
}; | ||
@@ -31,2 +32,3 @@ | ||
AwsHelper._AWS.config.region = AwsHelper.region; | ||
AwsHelper.log = AwsHelper.Logger(); | ||
return AwsHelper; | ||
@@ -56,2 +58,30 @@ } | ||
// This is a helper function that retrieves the headers from the event, that | ||
// depending on if it is an event from SNS, a lambda invoke, etc will return a | ||
// like-for-like object. | ||
AwsHelper._getEventHeaders = function () { | ||
var event = AwsHelper._event || {}; | ||
// This is a event header from an invocation of lambda or a API Gateway. | ||
var headers = event.headers; | ||
if (headers) { | ||
return headers; | ||
} | ||
if (event.Records && event.Records[0]) { | ||
var record = event.Records[0]; | ||
var attrs = record.Sns.MessageAttributes; | ||
if (attrs && Object.keys(attrs).length > 0) { | ||
headers = {}; | ||
Object.keys(attrs).map(function (key) { | ||
headers[key] = attrs[key].Value; | ||
}); | ||
return headers; | ||
} | ||
} | ||
// Default to an empty object | ||
return {}; | ||
}; | ||
// backwards compatability to retrieve the env from a givien context. | ||
@@ -78,2 +108,22 @@ // better to use AwsHelper(context).env; | ||
// If a trace-request-id is present on the header of the consuming lambda | ||
// then we will forward the tracing header to the new lambda instance when | ||
// being invoked. | ||
// | ||
// Eventually this payload should be move to: | ||
// { | ||
// body: { ... }, | ||
// headers: { | ||
// 'trace-request-id': 'some-id' | ||
// } | ||
// } | ||
// | ||
// Where { ... } is the current params.Payload. | ||
var headers = AwsHelper._getEventHeaders(); | ||
if (headers['trace-request-id']) { | ||
params.Payload.headers = { | ||
'trace-request-id': headers['trace-request-id'] | ||
}; | ||
} | ||
AwsHelper._initLambdaObject(); | ||
@@ -119,2 +169,4 @@ | ||
var headers = AwsHelper._getEventHeaders(); | ||
var p = { | ||
@@ -126,2 +178,11 @@ Message: params.Message, | ||
if (headers['trace-request-id']) { | ||
p.MessageAttributes = { | ||
'trace-request-id': { | ||
DataType: 'String', | ||
StringValue: headers['trace-request-id'] | ||
} | ||
}; | ||
} | ||
return AwsHelper._SNS.publish(p, cb); | ||
@@ -198,4 +259,3 @@ }; | ||
var context = AwsHelper._context || {}; | ||
var event = AwsHelper._event || {}; | ||
var headers = event.headers || {}; | ||
var headers = AwsHelper._getEventHeaders(); | ||
@@ -202,0 +262,0 @@ var log = bunyan.createLogger({ |
{ | ||
"name": "aws-lambda-helper", | ||
"version": "2.7.0", | ||
"version": "2.8.0", | ||
"description": "Collection of helper methods for lambda", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -75,3 +75,3 @@ # aws-lambda-helper | ||
//Initialise the helper by passing in the context | ||
AwsHelper.init(context); | ||
AwsHelper.init(context, event); | ||
@@ -78,0 +78,0 @@ var log = AwsHelper.Logger('example'); |
@@ -117,3 +117,38 @@ 'use strict'; | ||
}); | ||
it('should invoke the Lambda function MyAmazingLambda (using mock) with forwarded traceable ids', function (done) { | ||
var context = { | ||
'invokedFunctionArn': 'arn:aws:lambda:eu-west-1:123456789:function:aws-canary-lambda' | ||
}; | ||
AwsHelper.init(context, { headers: { 'trace-request-id': 'traceable-id' } }); | ||
AwsHelper._Lambda = new AwsHelper._AWS.Lambda(); | ||
// stub the lambda invoke function | ||
simple.mock(AwsHelper._Lambda, 'invoke').callFn(function (params, cb) { | ||
var p = { | ||
FunctionName: '123456789:MyAmazingLambda', | ||
InvocationType: 'RequestResponse', | ||
Payload: JSON.stringify({ 'hello': 'world', 'headers': { 'trace-request-id': 'traceable-id' } }), | ||
Qualifier: '$LATEST', | ||
LogType: 'None' | ||
}; | ||
assert.deepEqual(p, params); | ||
cb(null, {Payload: '{"totes": "worked"}'}); | ||
}); | ||
assert.equal(AwsHelper.version, '$LATEST'); // confirm correctly instantiated | ||
var params = { | ||
FunctionName: 'MyAmazingLambda', | ||
Payload: { 'hello': 'world' }, | ||
Qualifier: '' | ||
}; | ||
AwsHelper.Lambda.invoke(params, function (err, data) { | ||
assert(err === null); | ||
assert.deepEqual(data, { 'totes': 'worked' }); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -36,3 +36,3 @@ 'use strict'; | ||
}; | ||
AwsHelper.init(context); | ||
AwsHelper.init(context, { headers: { 'trace-request-id': 'an id' } }); | ||
var logger = AwsHelper.Logger(['stdout', 'test']); | ||
@@ -51,3 +51,55 @@ var stdout = ''; | ||
}); | ||
it('should log a json message with traceable_id', function (done) { | ||
var context = { | ||
'functionName': 'aws-canary-lambda', | ||
'invokedFunctionArn': 'arn:aws:lambda:eu-west-1:123456789:function:aws-canary-lambda:prod' | ||
}; | ||
AwsHelper.init(context, { headers: { 'trace-request-id': 'an id' } }); | ||
var logger = AwsHelper.Logger(['stdout', 'test']); | ||
var stdout = ''; | ||
var unhook = interceptStdout(function (text) { | ||
stdout += text; | ||
}); | ||
logger.info('hello in stdout'); | ||
setImmediate(function () { | ||
unhook(); | ||
var json = JSON.parse(stdout); | ||
assert.equal(json.traceable_id, 'an id'); | ||
done(); | ||
}); | ||
}); | ||
it('should log a json message with traceable_id', function (done) { | ||
var context = { | ||
'functionName': 'aws-canary-lambda', | ||
'invokedFunctionArn': 'arn:aws:lambda:eu-west-1:123456789:function:aws-canary-lambda:prod' | ||
}; | ||
AwsHelper.init(context, { | ||
Records: [ | ||
{ | ||
Sns: { | ||
MessageAttributes: { | ||
'trace-request-id': { | ||
Value: 'an id' | ||
} | ||
} | ||
} | ||
} | ||
] | ||
}); | ||
var logger = AwsHelper.Logger(['stdout', 'test']); | ||
var stdout = ''; | ||
var unhook = interceptStdout(function (text) { | ||
stdout += text; | ||
}); | ||
logger.info('hello in stdout'); | ||
setImmediate(function () { | ||
unhook(); | ||
var json = JSON.parse(stdout); | ||
assert.equal(json.traceable_id, 'an id'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -98,3 +98,40 @@ 'use strict'; | ||
}); | ||
it('should (Mock) publish the message to the topic (using mock) with a traceable id', function (done) { | ||
var context = { | ||
'invokedFunctionArn': 'arn:aws:lambda:eu-west-1:123456789:function:aws-canary-lambda:prod' | ||
}; | ||
AwsHelper.init(context, { headers: { 'trace-request-id': 'an id' } }); | ||
AwsHelper._SNS = new AwsHelper._AWS.SNS(); | ||
// stub the SNS.publish function | ||
simple.mock(AwsHelper._SNS, 'publish').callFn(function (params, cb) { | ||
var topic = 'arn:aws:sns:eu-west-1:123456789:my-awesome-topic-prod'; | ||
var p = { | ||
Message: params.Message, | ||
MessageStructure: 'json', | ||
TopicArn: topic, | ||
MessageAttributes: { | ||
'trace-request-id': { | ||
DataType: 'String', | ||
StringValue: 'an id' | ||
} | ||
} | ||
}; | ||
assert.deepEqual(p, params); | ||
cb(null, {MessageId: 'mock-message-id'}); | ||
}); | ||
var params = { | ||
Message: JSON.stringify({name: 'name'}), | ||
TopicArn: 'arn:aws:sns:eu-west-1:123456789:my-awesome-topic-prod' | ||
}; | ||
AwsHelper.SNS.publish(params, function (err, data) { | ||
assert(err === null); | ||
assert(data.MessageId === 'mock-message-id'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
125214
25
1201