1.0.0 • Published 5 years ago

ngx-aws4 v1.0.0

Weekly downloads
704
License
MIT
Repository
github
Last release
5 years ago

ngx-aws4

An utility to sign http(s) request options using Amazon's AWS Signature Version 4.

Installation

With npm do:

npm install ngx-aws4

Example

import * as aws4 from "ngx-aws4";

...

public static getAWS4Signature(url, path) {
	let requestOptions: any = {
		host: `${AWSCredentials.AWS_STS.BUCKET_NAME}.s3.${AWSCredentials.AWS_STS.REGION}.amazonaws.com`,
		path: path
	}

	console.log(aws4);

	aws4.sign(requestOptions, {
		secretAccessKey: AWSCredentials.AWS_STS.SECRET_KEY,
		accessKeyId: AWSCredentials.AWS_STS.ACCESS_KEY,
		sessionToken: AWSCredentials.AWS_STS.SESSION_TOKEN
	})
	console.log(requestOptions);

	return requestOptions;
}

...

More options

// you can also pass AWS credentials in explicitly (otherwise taken from process.env)
aws4.sign(opts, {accessKeyId: '', secretAccessKey: ''})

// can also add the signature to query strings
aws4.sign({service: 's3', path: '/my-bucket?X-Amz-Expires=12345', signQuery: true})

Thanks

Thanks to @mhart

Thanks to @jed

Also thanks to the official node.js AWS SDK