metalsmith-s3
v0.1.0
Published
A Metalsmith.io plugin to integrate with AWS S3
Downloads
286
Maintainers
Readme
metalsmith-s3
Metalsmith plugin for reading/writing/copying files on AWS S3.
Example usage: nonLinear.zone build process.
Installation
$ npm install metalsmith-s3
Usage
var Metalsmith = require('metalsmith');
var s3 = require('metalsmith-s3');
var metalsmith = new Metalsmith(__dirname)
.use(s3({
action: 'copy',
bucket: 's3-bucket-dest',
from: 's3-bucket-src',
prefix: ['images/', 'js/']
}));
.use(s3({
action: 'read',
bucket: 's3-bucket-src',
ignore: ['images/', 'js/']
}));
...
.use(s3({
action: 'write',
bucket: 's3-bucket-dest'
}));
S3 Library Pass Through
You can pass through additional settings directly to the s3 library by adding an s3
key and hash.
Properties available vary based on the chosen action:
Example to set the ACL for files written to s3:
var Metalsmith = require('metalsmith');
var s3 = require('metalsmith-s3');
var metalsmith = new Metalsmith(__dirname)
...
.use(s3({
action: 'write',
bucket: 's3-bucket-dest'
s3: {
ACL: 'public-read'
}
}));
Region Override
In case you face the following error, just add the optional parameter region : TypeError: Error: PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
Applicable regions are listed in aws documentation.
Usage example:
.use(s3({
action: 'write',
bucket: 's3-bucket-dest',
region: 'eu-west-1'
}));
Actions
Read
The read action will read files from an S3 bucket which can then be processed by plugins later in the chain. The read action can be modified to ignore certain prefixes in the S3 bucket be setting the ignore to a prefix, or an array of prefixes.
Read Parameters:
bucket: source S3 bucket
ignore: a prefix or array of prefixes not to be read from the source S3 bucket
region: bucket's endpoint region (optional)
Copy
The copy action will copy files from a source S3 bucket to a destination S3 bucket. The copy action must include a prefix parameter to specifiy one or more prefixes to be processed.
Copy Parameters
bucket: destination S3 bucket
from: source S3 bucket
prefix: a prefix or array of prefixes to be copied from the source S3 bucket
region: bucket's endpoint region (optional)
Write
The write action will write all files to the destination S3 bucket.
Write Parameters
bucket: destination S3 bucket
region: bucket's endpoint region (optional)
Mime Types
Uploaded file's mime type will be set by:
mimeType
property in the file's meta, if set- type determined by mime-type's inspection of the file name
- undefined (interpreted as
application/octet-stream
by S3)
Credentials configuration
Via environment variables
export AWS_ACCESS_KEY_ID='your_access_key'
export AWS_SECRET_ACCESS_KEY='your_secret_key'
Via configuration file
Create a credentials file at ~/.aws/credentials
on Mac/Linux or C:\Users\USERNAME\.aws\credentials
on Windows
[default]
aws_access_key_id = your_access_key
aws_secret_access_key = your_secret_key
TODO
- Test suite
#License
The MIT License (MIT)
Copyright © 2015, Matthew Wishek <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.