A library for AWS Signature Version 4
Switch branches/tags
develop feature/update-test-suite-url gh-pages greenkeeper/babel-loader-8.0.0 greenkeeper/babel-loader-8.0.1 greenkeeper/babel-loader-8.0.2 greenkeeper/babel-loader-8.0.3 greenkeeper/babel-loader-8.0.4 greenkeeper/babel-preset-env-1.5.0 greenkeeper/babel-preset-env-1.5.1 greenkeeper/babel-preset-env-pin-1.4.0 greenkeeper/coveralls-2.13.1 greenkeeper/coveralls-3.0.0 greenkeeper/coveralls-3.0.1 greenkeeper/eslint-5.0.0 greenkeeper/eslint-5.0.1 greenkeeper/mocha-3.3.0 greenkeeper/mocha-3.4.0 greenkeeper/mocha-3.4.1 greenkeeper/mocha-3.4.2 greenkeeper/mocha-4.0.0 greenkeeper/mocha-4.0.1 greenkeeper/mocha-4.1.0 greenkeeper/mocha-5.0.0 greenkeeper/mocha-5.0.1 greenkeeper/mocha-5.0.2 greenkeeper/mocha-5.0.3 greenkeeper/mocha-5.0.4 greenkeeper/mocha-5.0.5 greenkeeper/mocha-5.1.0 greenkeeper/mocha-5.1.1 greenkeeper/mocha-5.2.0 greenkeeper/mocha-loader-1.1.2 greenkeeper/mocha-loader-1.1.3 greenkeeper/mocha-loader-2.0.0 greenkeeper/mocha-pin-3.2.0 greenkeeper/nyc-11.2.0 greenkeeper/nyc-11.2.1 greenkeeper/nyc-11.3.0 greenkeeper/nyc-11.4.1 greenkeeper/nyc-11.6.0 greenkeeper/nyc-11.7.1 greenkeeper/nyc-11.7.2 greenkeeper/nyc-11.7.3 greenkeeper/nyc-11.8.0 greenkeeper/nyc-12.0.1 greenkeeper/nyc-12.0.2 greenkeeper/update-to-node-10 greenkeeper/webpack-4.0.0 greenkeeper/webpack-4.0.1 greenkeeper/webpack-4.1.0 greenkeeper/webpack-4.1.1 greenkeeper/webpack-4.2.0 greenkeeper/webpack-4.3.0 greenkeeper/webpack-4.4.0 greenkeeper/webpack-4.5.0 greenkeeper/webpack-4.6.0 greenkeeper/webpack-4.7.0 greenkeeper/webpack-4.8.2 greenkeeper/webpack-4.8.3 greenkeeper/webpack-4.9.0 greenkeeper/webpack-4.9.1 greenkeeper/webpack-4.9.2 greenkeeper/webpack-4.10.0 greenkeeper/webpack-4.10.1 greenkeeper/webpack-4.10.2 greenkeeper/webpack-4.11.0 greenkeeper/webpack-4.11.1 greenkeeper/webpack-4.12.0 greenkeeper/webpack-4.12.1 greenkeeper/webpack-4.12.2 greenkeeper/webpack-4.13.0 greenkeeper/webpack-4.14.0 greenkeeper/webpack-4.15.0 greenkeeper/webpack-4.15.1 greenkeeper/webpack-4.16.0 greenkeeper/webpack-4.16.1 greenkeeper/webpack-4.16.2 greenkeeper/webpack-4.16.3 greenkeeper/webpack-4.16.4 greenkeeper/webpack-4.16.5 greenkeeper/webpack-4.17.0 greenkeeper/webpack-4.17.1 greenkeeper/webpack-4.17.2 greenkeeper/webpack-4.17.3 greenkeeper/webpack-4.18.0 greenkeeper/webpack-4.18.1 greenkeeper/webpack-4.19.0 greenkeeper/webpack-4.19.1 greenkeeper/webpack-4.20.0 greenkeeper/webpack-4.20.1 greenkeeper/webpack-4.20.2 greenkeeper/webpack-4.21.0 greenkeeper/webpack-4.22.0 greenkeeper/webpack-4.23.0 greenkeeper/webpack-4.23.1 greenkeeper/webpack-4.24.0 greenkeeper/webpack-4.25.0 greenkeeper/webpack-4.25.1 greenkeeper/webpack-4.26.0 greenkeeper/webpack-4.26.1 greenkeeper/webpack-4.27.0 greenkeeper/webpack-4.27.1 greenkeeper/webpack-pin-2.4.1 master
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
scripts
src
test
.codeclimate.yml
.editorconfig
.esdoc.json
.eslintignore
.eslintrc.yml
.gitignore
.travis.yml
LICENSE
README.md
bower.json
deploy_key.enc
package.json
webpack.config.js
yarn.lock

README.md

aws-sigv4

A dependency-free, test suite-compliant, AWS Signature Version 4 library in ES2017

NPM npm version ESDoc Dependency Status devDependency Status Coverage Status Code Climate Test Coverage Issue Count Codacy Badge Known Vulnerabilities Greenkeeper badge

  • Master: Build Status
  • Develop: Build Status

Example - ES2017 (Node 7.6+)

const sigv4 = require('aws-sigv4');

const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
const requestDate = sigv4.formatDateTime(new Date());
const stringToSign = 'Test string to sign';

(async () => {
	const signature = await sigv4.sign(
		secretAccessKey,
		requestDate.slice(0, 8),
		'us-east-1',
		'host',
		stringToSign
	);

	console.log(signature);
})();

Example - ES2016 (Node 4, 6, <= 7.5)

const sigv4 = require('aws-sigv4');

const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
const requestDate = sigv4.formatDateTime(new Date());
const stringToSign = 'Test string to sign';

sigv4.sign(
	secretAccessKey,
	requestDate.slice(0, 8),
	'us-east-1',
	'host',
	stringToSign
)
	.then(signature => console.log(signature));

Or, more specifically for S3:

const sigv4 = require('aws-sigv4');

const date = sigv4
	.formatDateTime(new Date())
	.slice(0, 8);
const credential = `${process.env.AWS_ACCESS_KEY_ID}/${date}/${process.env.AWS_REGION}/s3/aws4_request`;
const policy = new Buffer(
	JSON.stringify({
		expiration: new Date(Date.now() + 15 * 60000).toISOString(), // 15 minutes from now
		conditions: [
			{bucket: 'my-bucket-name'},
			{key: 'my-s3-key.mov'},
			{acl: 'private'},
			['starts-with', '$Content-Type', 'video/'],
			['content-length-range', 0, 10 * 1024 * 1024],
			{'x-amz-credential': credential},
			{'x-amz-algorithm': 'AWS4-HMAC-SHA256'},
			{'x-amz-date': date + 'T000000Z'}
		]
	})
)
	.toString('base64');

sigv4.sign(
	process.env.AWS_SECRET_ACCESS_KEY,
	date,
	process.env.AWS_REGION,
	's3',
	policy
)
	.then(signature => console.log(signature));

See Authenticating Requests in Browser-Based Uploads Using POST (AWS Signature Version 4) as the primary use case.