Skip to content
/ aws Public

Thin wrappers around the aws-sdk libraries we use.

Notifications You must be signed in to change notification settings

SparkPost/aws

Repository files navigation

Build Status

aws

Thin wrappers around the aws-sdk libraries we use.

Initialization

Rather than having to assemble all the necessary connection config in every file that needs aws services, this wrapper provides a simple way to set up the AWS credentials in one place, one time for the whole service. This also allows the service to remove this initialization step later in favor of ENV_VAR or instance profile auth management, if possible.

For example, in app.js:

'use strict';

const AWS = require('@sparkpost/aws');
// ... whatever else you need, besides the actual models etc. that use aws

/*
 * This needs to occur before the resources module tree is required
 * because the AWS module needs to be globally configured before any
 * usage / instantiation can occur.
 */
if (config.get('aws.enabled') && config.get('aws.enabled') === true) {
  AWS.initialize({
    accessKeyId: config.get('aws.accessKeyId'),
    secretAccessKey: passwords.maybeDecrypt(config.get('aws.secretAccessKey')),
    region: config.get('aws.region'),
    proxy: process.env.HTTPS_PROXY
  });
}

// the files that use aws are required *after* the setup (note: better auth strategies might avoid this order-dependencies in the future)
const resources = require('./resources');

AWS SDK Client

If you want access to the raw aws-sdk client you can use the SDK property.

const AWS = require('@sparkpost/aws');
const marketplaceMeteringService = new AWS.SDK.MarketplaceMetering({ apiVersion: '2016-01-14' });
marketplaceMeteringService.resolveCustomer({ RegistrationToken: token }, (err, data) => { ... });

Supported Services