evanshortiss / sns-mobile

Push notifications to Android, Kindle, and iOS devices easily using this module.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow sns-mobile to take in a reference to an AWS SNS object

SundeepK opened this issue · comments

Currently sns-mobile always constructs an AWS SNS object for internal use and abstracts this away from the client. However, there are many options that the SNS object can take AWS js Doc.

Allowing clients to pass in their own SNS object allows them to fully configure however they want to, and allow sns-mobile to abstract away the appropriate code to do mobile push. Also, this way we don't need to always supply AWS key and secret. This would be a problem for servers which work on IAM roles.

I can have a crack at fixing this when I get time since it is something that I need and send a pull request.

Hi @SundeepK

I can see why this would be useful and I'd be happy to merge a PR for this feature.

We could maybe cover 2 scenarios: (both would be backwards compatible)

  • Allow user provide their own instance of AWS.SNS (first code example)
  • Allow user provide all options for AWS.SNS without any wrapping (second example)
if (!opts.sns) {
  this.sns = new AWS.SNS({
    region: opts.region,
    apiVersion: opts.apiVersion,
    accessKeyId: opts.accessKeyId,
    secretAccessKey: opts.secretAccessKey
  });
} else {
  this.sns = opts.sns;
}

or something like this:

if (opts.sns) {
  this.sns = new AWS.SNS(opts.sns);
} else {
  this.sns = new AWS.SNS({
    region: opts.region,
    apiVersion: opts.apiVersion,
    accessKeyId: opts.accessKeyId,
    secretAccessKey: opts.secretAccessKey
  });
}

All three could actually be covered if we had a third check that inspected opts.sns to see is it an AWS.SNS instance.

Oh yes, very good suggestion & PR imho, as it allows the module to play nicely with IAM roles.

Apologies for the delay. I see the PR and will merge in the coming days.