How to use the aws-sdk.SNS function in aws-sdk

To help you get started, we’ve selected a few aws-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PRX / Infrastructure / ci / lambdas / github-event-handler / index.js View on Github external
// 1. Check to make sure this event should trigger a build
// 2. Trigger a CodeBuild by copying current code to S3 (the CodeBuild source)
// 3. Send a notification that the build is starting (for Slack/etc)
// 4. Set the GitHub status to 'pending' for the sha
// This Lambda should not be considered to be entirely or even mostly
// responsible for the configuration of CodeBuild environment. It should only
//  worry about the parts of the configuration that result from the events
// the function is intended to handle.

const url = require('url');
const https = require('https');
const fs = require('fs');
const AWS = require('aws-sdk');

const codebuild = new AWS.CodeBuild({ apiVersion: '2016-10-06' });
const sns = new AWS.SNS({ apiVersion: '2010-03-31' });
const s3 = new AWS.S3({ apiVersion: '2006-03-01' });

const USER_AGENT = 'PRX/Infrastructure (github-event-handler)';
const GITHUB_HEADERS = {
    Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN}`,
    Accept: 'application/vnd.github.v3+json',
    'User-Agent': USER_AGENT,
};

// Note: The response to this request should be a 201
// https://developer.github.com/v3/repos/statuses/#create-a-status
function updateGitHubStatus(event, build) {
    return (new Promise((resolve, reject) => {
        console.log('...Updating GitHub status...');

        // Get request properties
github serverless / serverless / tests / utils / index.js View on Github external
createSnsTopic(topicName) {
    const SNS = new AWS.SNS({ region: 'us-east-1' });
    BbPromise.promisifyAll(SNS, { suffix: 'Promised' });

    const params = {
      Name: topicName,
    };

    return SNS.createTopicPromised(params);
  },
github architect / functions / src / events / publish-old.js View on Github external
function _scan({eventName}, callback) {
  let sns = new aws.SNS()
  ;(function __scanner (params = {}, callback) {
    sns.listTopics(params, function _listTopics(err, results) {
      if (err) throw err
      let found = results.Topics.find(t => {
        let bits = t.TopicArn.split(':')
        let it = bits[bits.length - 1]
        return it === eventName
      })
      if (found) {
        callback(null, found.TopicArn)
      } else if (results.NextToken) {
        __scanner({ NextToken: results.NextToken }, callback)
      } else {
        callback(Error(`topic ${eventName} not found`))
      }
    })
github awslabs / video-on-demand-on-aws / source / publish / lib / error.js View on Github external
let errSns = function(event,_err) {
   console.log('Running Error Handler');

   const sns = new AWS.SNS({region: process.env.AWS_REGION});

   let msg = {
     "guid": event.guid,
     "event":event,
     "function":process.env.AWS_LAMBDA_FUNCTION_NAME,
     "error": _err.toString()
   };

   let params = {
         Subject: 'Workflow error: ' + event.guid,
         Message: JSON.stringify(msg, null, 2),
         TargetArn: process.env.ErrorsSns
     };

   sns.publish(params).promise()
     .catch(err => console.log(err)
github serverless-examples / serverless-cd-example / v0.5 / src / books / post / snsPublish.js View on Github external
var AWS = require('aws-sdk');
var sns = new AWS.SNS();

if(process.env.IS_UNIT_TEST === 'true') {
  module.exports = function(message, topicArn, cb) {
    cb(null, {});
  };

} else {
  module.exports = function(message, topicArn, cb) {
    var params = {
      Message: JSON.stringify(message),
      TopicArn: topicArn
    };

    sns.publish(params, cb);
  };
}
github lifeomic / lambda-tools / src / localstack.js View on Github external
    getClient: ({ config }) => new AWS.SNS(config),
    isReady: (client) => client.getSMSAttributes().promise()
github martinlindenberg / serverless-plugin-sns / index.js View on Github external
.then(function(creds) {
                _this.sns = new AWS.SNS({
                    region: region,
                    accessKeyId: creds.accessKeyId,
                    secretAccessKey: creds.secretAccessKey,
                    sessionToken: creds.sessionToken
                });

                BbPromise.promisifyAll(_this.sns);

                _this.lambda = new AWS.Lambda({
                    region: region,
                    accessKeyId: creds.accessKeyId,
                    secretAccessKey: creds.secretAccessKey,
                    sessionToken: creds.sessionToken
                });
            })
        }
github manwaring / odin / stacks / check.js View on Github external
'use strict';
const AWS = require('aws-sdk');
const cloudFormation = new AWS.CloudFormation({ apiVersion: '2010-05-15' });
const sns = new AWS.SNS({ apiVersion: '2010-03-31' });
const log = require('console-log-level')({ level: process.env.LOG_LEVEL });

module.exports.handler = (event, context, callback) => {
  log.trace('Received event to check stacks for automatic deletion with configuration', event);
  log.info('Odin is now checking to see if any stacks are worthy of entering Valhalla');

  listAllStacks()
    .then( stacks => getStacksToDelete(stacks, event))
    .then(publishStacksForDeletion)
    .then( () => callback(null, 'Finished checking stacks for deletion'))
    .catch( err => callback(err));
};

const listAllStacks = () => {
  const params = {};
  return cloudFormation.describeStacks(params).promise();
github theburningmonk / lambda-correlation-id-demo / lib / sns.js View on Github external
const AWS            = require('aws-sdk');
const SNS            = 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;
}
github bkenio / tidal / src / lib / events.js View on Github external
constructor({ videoId, snsTopicArn, region }) {
    super();
    this.videoId = videoId;
    this.snsTopicArn = snsTopicArn;
    this.sns = new AWS.SNS({ region });
  }