aws4
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The aws4 npm package is a compact utility that signs vanilla Node.js http(s) request options using Amazon's AWS Signature Version 4. This assists in bolstering the authentication of your AWS services which, with the exception of SimpleDB, all support AWS Signature Version 4. The module not only signs your requests, but also provides defaults for numerous core AWS request headers and parameters to simplify developing on AWS services.
Using aws4 is quite straightforward and flexible. It is designed to work with the objects you would typically pass as options to Node.js's http(s) request methods. Here is a simplified example with Node.js's https library:
var https = require('https')
var aws4 = require('aws4')
function request(opts) { https.request(opts, function(res) { res.pipe(process.stdout) }).end(opts.body || '') }
var opts = { host: 'my-bucket.s3.us-west-1.amazonaws.com', path: '/my-object' }
aws4.sign(opts)
request(opts)
In this example, a simple HTTP request is made to an S3 bucket. Before making the request, it's signed by aws4, which enhances request authentication. aws4 also allows you to pass AWS service specific regions, add headers, or even sign the query if needed. You can find more detailed and elaborate examples in the official documentation.
Your AWS credentials can be specified either as the second argument in the aws4.sign function:
aws4.sign(requestOptions, {
secretAccessKey: "<your-secret-access-key>",
accessKeyId: "<your-access-key-id>",
sessionToken: "<your-session-token>"
})
Or it can automatically read from your environment variables:
export AWS_ACCESS_KEY_ID="<your-access-key-id>"
export AWS_SECRET_ACCESS_KEY="<your-secret-access-key>"
export AWS_SESSION_TOKEN="<your-session-token>"
The official documentation for the AWS4 npm package can be found on npmjs.com and the Github page. Here, you can get more in-depth information on the full capabilities of the package, additional example usages, installation steps and more. Also given its popularity and wide usage, there are various blogs and third-party sites offering guides and tutorials on how to harness the power of AWS4 in your JavaScript project.