Gathering detailed insights and metrics for aws4
Gathering detailed insights and metrics for aws4
Gathering detailed insights and metrics for aws4
Gathering detailed insights and metrics for aws4
Signs and prepares Node.js requests using AWS Signature Version 4
npm install aws4
Typescript
Module System
Node Version
NPM Version
99.7
Supply Chain
99.5
Quality
85.3
Maintenance
100
Vulnerability
100
License
JavaScript (99.89%)
HTML (0.11%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
6,306,183,029
Last Day
1,066,383
Last Week
19,888,948
Last Month
80,758,813
Last Year
951,381,183
MIT License
710 Stars
163 Commits
176 Forks
9 Watchers
2 Branches
10 Contributors
Updated on Feb 13, 2025
Minified
Minified + Gzipped
Latest Version
1.13.2
Package Id
aws4@1.13.2
Unpacked Size
22.85 kB
Size
7.96 kB
File Count
5
NPM Version
10.8.2
Node Version
22.5.1
Published on
Aug 28, 2024
Cumulative downloads
Total Downloads
Last Day
-21.7%
1,066,383
Compared to previous day
Last Week
-6.7%
19,888,948
Compared to previous week
Last Month
24.9%
80,758,813
Compared to previous month
Last Year
-6.3%
951,381,183
Compared to previous year
A small utility to sign vanilla Node.js http(s) request options using Amazon's AWS Signature Version 4.
If you want to sign and send AWS requests in a modern browser, or an environment like Cloudflare Workers, then check out aws4fetch – otherwise you can also bundle this library for use in older browsers.
The only AWS service that doesn't support v4 as of 2020-05-22 is SimpleDB (it only supports AWS Signature Version 2).
It also provides defaults for a number of core AWS headers and request parameters, making it very easy to query AWS services, or build out a fully-featured AWS library.
1var https = require('https') 2var aws4 = require('aws4') 3 4// to illustrate usage, we'll create a utility function to request and pipe to stdout 5function request(opts) { https.request(opts, function(res) { res.pipe(process.stdout) }).end(opts.body || '') } 6 7// aws4 will sign an options object as you'd pass to http.request, with an AWS service and region 8var opts = { host: 'my-bucket.s3.us-west-1.amazonaws.com', path: '/my-object', service: 's3', region: 'us-west-1' } 9 10// aws4.sign() will sign and modify these options, ready to pass to http.request 11aws4.sign(opts, { accessKeyId: '', secretAccessKey: '' }) 12 13// or it can get credentials from process.env.AWS_ACCESS_KEY_ID, etc 14aws4.sign(opts) 15 16// for most AWS services, aws4 can figure out the service and region if you pass a host 17opts = { host: 'my-bucket.s3.us-west-1.amazonaws.com', path: '/my-object' } 18 19// usually it will add/modify request headers, but you can also sign the query: 20opts = { host: 'my-bucket.s3.amazonaws.com', path: '/?X-Amz-Expires=12345', signQuery: true } 21 22// and for services with simple hosts, aws4 can infer the host from service and region: 23opts = { service: 'sqs', region: 'us-east-1', path: '/?Action=ListQueues' } 24 25// and if you're using us-east-1, it's the default: 26opts = { service: 'sqs', path: '/?Action=ListQueues' } 27 28aws4.sign(opts) 29console.log(opts) 30/* 31{ 32 host: 'sqs.us-east-1.amazonaws.com', 33 path: '/?Action=ListQueues', 34 headers: { 35 Host: 'sqs.us-east-1.amazonaws.com', 36 'X-Amz-Date': '20121226T061030Z', 37 Authorization: 'AWS4-HMAC-SHA256 Credential=ABCDEF/20121226/us-east-1/sqs/aws4_request, ...' 38 } 39} 40*/ 41 42// we can now use this to query AWS 43request(opts) 44/* 45<?xml version="1.0"?> 46<ListQueuesResponse xmlns="https://queue.amazonaws.com/doc/2012-11-05/"> 47... 48*/ 49 50// aws4 can infer the HTTP method if a body is passed in 51// method will be POST and Content-Type: 'application/x-www-form-urlencoded; charset=utf-8' 52request(aws4.sign({ service: 'iam', body: 'Action=ListGroups&Version=2010-05-08' })) 53/* 54<ListGroupsResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/"> 55... 56*/ 57 58// you can specify any custom option or header as per usual 59request(aws4.sign({ 60 service: 'dynamodb', 61 region: 'ap-southeast-2', 62 method: 'POST', 63 path: '/', 64 headers: { 65 'Content-Type': 'application/x-amz-json-1.0', 66 'X-Amz-Target': 'DynamoDB_20120810.ListTables' 67 }, 68 body: '{}' 69})) 70/* 71{"TableNames":[]} 72... 73*/ 74 75// The raw RequestSigner can be used to generate CodeCommit Git passwords 76var signer = new aws4.RequestSigner({ 77 service: 'codecommit', 78 host: 'git-codecommit.us-east-1.amazonaws.com', 79 method: 'GIT', 80 path: '/v1/repos/MyAwesomeRepo', 81}) 82var password = signer.getDateTime() + 'Z' + signer.signature() 83 84// see example.js for examples with other services
Calculates and populates any necessary AWS headers and/or request
options on requestOptions
. Returns requestOptions
as a convenience for chaining.
requestOptions
is an object holding the same options that the Node.js
http.request
function takes.
The following properties of requestOptions
are used in the signing or
populated if they don't already exist:
hostname
or host
(will try to be determined from service
and region
if not given)method
(will use 'GET'
if not given or 'POST'
if there is a body
)path
(will use '/'
if not given)body
(will use ''
if not given)service
(will try to be calculated from hostname
or host
if not given)region
(will try to be calculated from hostname
or host
or use 'us-east-1'
if not given)signQuery
(to sign the query instead of adding an Authorization
header, defaults to false)headers['Host']
(will use hostname
or host
or be calculated if not given)headers['Content-Type']
(will use 'application/x-www-form-urlencoded; charset=utf-8'
if not given and there is a body
)headers['Date']
(used to calculate the signature date if given, otherwise new Date
is used)Your AWS credentials (which can be found in your AWS console) can be specified in one of two ways:
1aws4.sign(requestOptions, { 2 secretAccessKey: "<your-secret-access-key>", 3 accessKeyId: "<your-access-key-id>", 4 sessionToken: "<your-session-token>" 5})
process.env
, such as this: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>"
(will also use AWS_ACCESS_KEY
and AWS_SECRET_KEY
if available)
The sessionToken
property and AWS_SESSION_TOKEN
environment variable are optional for signing
with IAM STS temporary credentials.
With npm do:
npm install aws4
Can also be used in the browser.
Thanks to @jed for his dynamo-client lib where I first committed and subsequently extracted this code.
Also thanks to the official Node.js AWS SDK for giving me a start on implementing the v4 signature.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
Found 1/27 approved changesets -- score normalized to 0
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More