Skip to content

Commit

Permalink
Test messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgfindl committed Jan 5, 2018
1 parent 2584e78 commit d44e34a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
4 changes: 2 additions & 2 deletions _cim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ stack:
AppName: 'app'

# Build Notification
# NotificationEmail: '[email protected]'
NotificationEmail: '[email protected]'
# NotificationSMS: '1-410-336-xxxx'
#NotificationSMS: '1-410-336-xxxx'
NotificationSlack: 'http:https://slack.com/test'

#
# Define stack capabilities required.
Expand Down
12 changes: 9 additions & 3 deletions stacks/notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@ const async = require('async');
const _ = require('lodash');

const slack = require('./lib/slack');
const sns = require('./lib/sns');

var functions = {};

functions.slack = function(event, context) {
winston.info('slack');
winston.info(JSON.stringify(event));
winston.info(JSON.stringify(event.Records[0].Sns.Message));
context.succeed();
};

functions.events = function(event, context) {
winston.info('events');
winston.info(JSON.stringify(event));
context.succeed();
winston.info(JSON.stringify(event.Records[0].Sns.Message));
sns.publish({
topic: process.env.NotificationTopic,
message: JSON.stringify(event.Records[0].Sns.Message)
}, function(err, results) {
context.succeed();
});
};

module.exports = functions;
23 changes: 23 additions & 0 deletions stacks/notifications/lib/sns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const AWS = require('aws-sdk');
const sns = new AWS.SNS();
const winston = require('winston');

var functions = {};

//
// Send response back to Meridian's Event API over SNS
//
functions.publish = function(input, done) {
winston.info('sns.publish');

var params = {
TopicArn: input.topic,
Message: input.message
};
winston.info(JSON.stringify(params));
sns.publish(params, done);
};

module.exports = functions;
2 changes: 1 addition & 1 deletion stacks/notifications/notifications.stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Resources:
Runtime: nodejs6.10
Environment:
Variables:
SLACK_HOOK_URL: !Ref NotificationSlack
NotificationSlack: !Ref NotificationSlack

#
# Subscribe our new Lambda function to the SNS topic.
Expand Down
22 changes: 22 additions & 0 deletions stacks/notifications/test/resources/push-image-01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"Records": [
{
"EventSource": "aws:sns",
"EventVersion": "1.0",
"EventSubscriptionArn": "arn:aws:sns:us-east-1:132093761664:app-devops-events:91aff27b-fa19-4a96-b6ae-2e359169a528",
"Sns": {
"Type": "Notification",
"MessageId": "0823695d-b2b4-5ee7-adc7-3b94c56fa175",
"TopicArn": "arn:aws:sns:us-east-1:132093761664:app-devops-events",
"Subject": "app-prod version 1ce8d5c6 is ready.",
"Message": "app-prod version 1ce8d5c6 is ready.",
"Timestamp": "2018-01-05T12:54:51.795Z",
"SignatureVersion": "1",
"Signature": "QKOw80cpH+6mLkveDw/4VIcVOK61qLye+sqfMZZEXXb9KXf7k5rVvLBkgagEeWadMWQqBlSDzYqSZiIh8gsIl8vOF6nsSaW3Xf+pNEBsV/kWnccPLbUGUf7A/RZevFzZ6I7eGXAzNB/cQb0KQO4VvbscYRbDUR+oY850wjwqDVT3MucYfzu90c0EoFOb4I7vG7/89f/DOTPjljKehDqykjz19hLIFDyboOSwsR4vpmQe6EiVWCOg0B/gyWd4xOuKwOvDDeHf+BbKSyexYHBErAA0gdXEvjm9UEJv5/pOCi/k5zCZrG5jy7C0/yt0FilWl0B3SfP2EyI0DJkjx0RIiA==",
"SigningCertUrl": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-433026a4050d206028891664da859041.pem",
"UnsubscribeUrl": "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:132093761664:app-devops-events:91aff27b-fa19-4a96-b6ae-2e359169a528",
"MessageAttributes": {}
}
}
]
}

0 comments on commit d44e34a

Please sign in to comment.