Skip to content

Instantly share code, notes, and snippets.

@theburningmonk
Created August 28, 2017 14:29
Show Gist options
  • Save theburningmonk/b4da28d6a78798bbbf6aa57c462eea62 to your computer and use it in GitHub Desktop.
Save theburningmonk/b4da28d6a78798bbbf6aa57c462eea62 to your computer and use it in GitHub Desktop.
'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