Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including ec2-sns with all npm packages installed. Try it out:

var ec2Sns = require("ec2-sns")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

ec2-sns v1.0.17

AWS SNS client that automatically subscribes to topic and unsubscribes when terminated. Designed especially for AWS EC2 Instances and Docker

npm Travis build status Coveralls

EC2 SNS Client

AWS SNS Client that:

  • automatically subscribes to SNS topic,
  • gets endpoint URL from EC2 instance public IP

Designed to run in AWS ECS / Docker environment.

Usage

const SNS = require('ec2-sns');
const sns = new SNS({
  port: 8081 // default port
});

// receive messages from SNS Topic
sns.on('message', message => {
  console.log('Subject', message.subject);
  console.log('Body', message.body); // must be JSON
});

// send message to SNS Topic
sns.on('ready', () => {
  sns.send({
    subject: 'my-subject',
    message: {foo: 'bar'}
  });
});

Environment variables

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_TOPIC_ARN (SNS topic has to be created first)
  • AWS_REGION (optional, defaults to eu-west-1)
  • AWS_SUBSCRIPTION_ENDPOINT (optional, overrides automatic one)
  • NO_SUBSCRIPTION (optional) if set it won't subscribe, but still can send messages to SNS Topic

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free