diff --git a/README.md b/README.md index e879ac4..1a789bf 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,13 @@ ember install ember-cli-deploy-elastic-beanstalk ## A Note on AWS Permissions -This plugin relies on the official AWS SDK to perform uploads to S3. As +This plugin uses the official AWS SDK to perform uploads to S3. As such, it will inherit any credentials you have saved by running `aws -configure` via the [AWS CLI][aws-cli]. +configure` via the [AWS CLI][aws-cli]. For environments where it is not feasible +to use `aws configure` (e.g. your CI environment like Travis), you can additionally +specify an `accessKeyId` and `secretAccessKey` as a configuration option for this +ember-cli-deploy plugin in the `deploy.js` file. + [aws-cli]: https://aws.amazon.com/cli/ @@ -123,6 +127,20 @@ The path to the zip file that should be created from the `outputPath`. *Default:* `tmp/fastboot-dist.zip` + +### accessKeyId + +The AWS access key for the user that has the ability to upload to the `bucket`. If this is left undefined, +the normal [AWS SDK credential resolution][5] will take place. + +*Default:* `undefined` + +### secretAccessKey + +The AWS secret for the user that has the ability to upload to the `bucket`. This must be defined when `accessKeyId` is defined. + +*Default:* `undefined` + ### filesToExclude Files that match this pattern will be excluded from the `zip`. For instance to diff --git a/lib/aws/s3.js b/lib/aws/s3.js index 2c8dee5..f687472 100644 --- a/lib/aws/s3.js +++ b/lib/aws/s3.js @@ -5,11 +5,16 @@ const AWS = require('aws-sdk'); class S3 { constructor(options) { options = options || {}; - - this.s3 = new AWS.S3({ + let s3Options = { apiVersion: '2006-03-01', region: options.region - }); + }; + if (options.accessKeyId && options.secretAccessKey) { + s3Options.accessKeyId = options.accessKeyId; + s3Options.secretAccessKey = options.secretAccessKey; + } + + this.s3 = new AWS.S3(s3Options); } listBuckets() { diff --git a/lib/elastic-beanstalk-deploy-plugin.js b/lib/elastic-beanstalk-deploy-plugin.js index 4f02ab8..6163c88 100644 --- a/lib/elastic-beanstalk-deploy-plugin.js +++ b/lib/elastic-beanstalk-deploy-plugin.js @@ -66,6 +66,8 @@ module.exports = DeployPlugin.extend({ let region = this.readConfig('region'); let bucket = this.readConfig('bucket'); let key = this.readConfig('key'); + let accessKeyId = this.readConfig('accessKeyId'); + let secretAccessKey = this.readConfig('secretAccessKey'); let uploadTask = new UploadTask({ context: context, @@ -73,7 +75,9 @@ module.exports = DeployPlugin.extend({ hashedZipPath: context.hashedZipPath, region: region, bucket: bucket, - key: key + key: key, + accessKeyId: accessKeyId, + secretAccessKey: secretAccessKey }); return uploadTask.run(); diff --git a/lib/tasks/upload.js b/lib/tasks/upload.js index a7389a4..fec0ade 100644 --- a/lib/tasks/upload.js +++ b/lib/tasks/upload.js @@ -12,7 +12,13 @@ class UploadTask { this.key = options.key; this.hashedZipPath = options.hashedZipPath; this.hashedZipKey = path.basename(this.hashedZipPath); - this.s3 = new S3({ region: options.region }); + + let s3Opts = { region: options.region }; + if (options.accessKeyId && options.secretAccessKey) { + s3Opts.accessKeyId = options.accessKeyId; + s3Opts.secretAccessKey = options.secretAccessKey; + } + this.s3 = new S3(s3Opts); } run() {