Skip to content

Instantly share code, notes, and snippets.

@marekkrzynowek
Created December 4, 2019 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marekkrzynowek/23745c9777f2fd35ec049e941bd49949 to your computer and use it in GitHub Desktop.
Save marekkrzynowek/23745c9777f2fd35ec049e941bd49949 to your computer and use it in GitHub Desktop.
const utils = require('@ucapp/unioncore-utils');
const AWS = require('aws-sdk');
module.exports.helloWorld = async (event, context) => {
context.callbackWaitsForEmptyEventLoop = false;
try {
const msgs = [];
for (const r of event.Records) {
const payload = _extractMessageFromPayload(r);
// Do stuff with the payload.
await utils.publishToSNS(
new AWS.SNS({ apiVersion: '2010-03-31' }), {
Message: JSON.stringify(payload),
TopicArn: process.env.HELLO_TOPIC,
},
);
msgs.push(payload.message);
console.log('Payload', payload);
}
return utils.buildResponse({
statusCode: 200,
body: {
message: msgs.join(' ')
}
});
} catch(err) {
console.log('Error: ', err.message);
throw err;
}
};
function _extractMessageFromPayload(response) {
const body = JSON.parse(response.body);
return JSON.parse(body.Message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment