Created
August 28, 2017 14:29
-
-
Save theburningmonk/b4da28d6a78798bbbf6aa57c462eea62 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
const co = require('co'); | |
const Promise = require('bluebird'); | |
const AWS = require('aws-sdk'); | |
const SNS = Promise.promisifyAll(new AWS.SNS()); | |
const log = require('./log'); | |
const requestContext = require('./requestContext'); | |
function getMessageAttributes() { | |
let attributes = {}; | |
let ctx = requestContext.get(); | |
for (let key in ctx) { | |
attributes[key] = { | |
DataType: 'String', | |
StringValue: ctx[key] | |
}; | |
} | |
return attributes; | |
} | |
let publish = co.wrap(function* (topicArn, msg) { | |
let req = { | |
Message: msg, | |
MessageAttributes: getMessageAttributes(), | |
TopicArn: topicArn | |
}; | |
yield SNS.publishAsync(req); | |
}); | |
module.exports = { | |
publish | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment