1.4.0 • Public • Published

Build Status npm version

AWS Signature V4

Generating the "new" AWS V4 signatures can be a bit of a pain.

For instance if you need to generate a signed URL for S3 where you have a key, secret and bucket. The steps to actually sign it is an order of magnitude more complicated than what the AWS V2 signatures were.

Just have a look at their own docs.

This module exists to provide some help. It does those steps in their example for you and provides you with a simple way to sign an S3 URL mainly, but also a more simplified way to sign any AWS URL.


This is the easiest example how you may sign an S3 GET URL (assuming you have set your AWS ENV vars set up):

var v4 = require('aws-signature-v4');
var url = v4.createPresignedS3URL('logs/my-file.txt');
// url => ""

Say you want to upload using HTTP, for instance with this neat component you can also do this in a /sign route :

var v4 = require('aws-signature-v4');
var url = v4.createPresignedS3URL(, {
  region: 'eu-central-1', // using frankfurt which requires V4 at the moment
  expires: 3600, // need to upload within 1 hour
  method: 'PUT',
  headers: {
    'x-amz-acl': 'public-read' // set the uploaded file ACL to public-read


It's available on npm so you can simply install it with:

npm install --save aws-signature-v4


AWS ENV vars

I've tried to use the "official" ENV vars by default in this module. The ones they use in their own SDK:

  • AWS_S3_BUCKET (not really official, but useful)

Public API

createPresignedS3URL(name[, options])

Returns a query-signed AWS URL with some S3 service specifics.

Options may be any of createPresignedURLs options plus:

  • method (defaults to "GET")
  • bucket (defaults to process.env.AWS_S3_BUCKET)

createPresignedURL(method, host, path, service, payload[, options])

Returns a query-signed AWS URL.

  • key (defaults to process.env.AWS_ACCESS_KEY_ID)
  • secret (defaults to process.env.AWS_SECRET_ACCESS_KEY)
  • sessionToken (defaults to process.env.AWS_SESSION_TOKEN)
  • protocol (defaults to "https")
  • headers (defaults to {})
  • timestamp (defaults to
  • region (defaults to process.env.AWS_REGION || "us-east-1")
  • expires (defaults to 86400, or 24 hours)
  • query Optional query parameters attached to the AWS API call (defaults to none)

Internal API (but still available)

createCanonicalRequest(method, pathname, query, headers, payload)

Returns a CanonicalRequest as defined by query-signed AWS URL docs.


Returns a CanonicalQueryString as defined by query-signed AWS URL docs.


Returns a CanonicalHeaders as defined by query-signed AWS URL docs.


Returns the Signed Headers as defined by query-signed AWS URL docs.

createCredentialScope(time, region, service)

Returns the Credential Scope as defined by query-signed AWS URL docs.

createStringToSign(time, region, service, request)

Returns the StringToSign as defined by query-signed AWS URL docs.

createSignature(secret, time, region, service, stringToSign)

Returns the Signature as defined by query-signed AWS URL docs.

Package Sidebar


npm i aws-signature-v4

Weekly Downloads






Unpacked Size

81.3 kB

Total Files


Last publish


  • slaskis