Skip to content

roxtar/s3sign.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

s3sign.js

s3sign.js is a lightweight JavaScript library to generate signed S3 URLs. It can be run in a browser and in NodeJS. The s3sign.js library depends on CryptoJS.

The total unminified code size is 14.5 KB, which is much smaller than aws-sdk.js whose minified version is 239 KB today.

  • s3sign.js - 6.4 KB
  • CyrptoJS - 8.1 KB

Most of the code is a straight JavaScript port from the s3-signed-url Perl script.

Demo

You can see a demo here.

Usage

Browser

Include the following scripts in your HTML

  <script src="CryptoJS/hmac-sha1.js"></script>
  <script src="CryptoJS/enc-base64.js"></script>
  <script src="s3sign.js"></script>

Wherever you want to generate a signed URL, you can call

  <script type="text/javascript">
   var signedUrl = s3sign.generateSignedUrl(
        accessKey,            // AWS Access Key
        secretKey,            // AWS secret Key
        expiresInSeconds,     // Expiration time in seconds from now
        httpMethod,           // HTTP method. GET, POST, etc
        s3Bucket,             // Your S3 bucket name
        path                  // Path to your S3 key. Do not include the bucket name in this.
        );

  </script>

NodeJS

Installation:

  npm install s3sign

Example code:

  var s3sign = require("s3sign");
  var signedUrl = s3sign.generateSignedUrl(
        accessKey,            // AWS Access Key
        secretKey,            // AWS secret Key
        expiresInSeconds,     // Expiration time in seconds from now 
        httpMethod,           // HTTP method. GET, POST, etc
        s3Bucket,             // Your S3 bucket name.
        path                  // Path to your S3 key. Do not include the bucket name in this.
        );

About

Small JavaScript library to create signed S3 URLs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published