GithubHelp home page GithubHelp logo

web5design / amazon-s3-url-signer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dyashkir/amazon-s3-url-signer

0.0 3.0 0.0 160 KB

Node.js module to create and sign URLs to access private resources on Amazon S3

amazon-s3-url-signer's Introduction

##Amazon S3 url signer

Module to sign urls to allow access to the private resources in the S3

NPM

###To install

npm install amazon-s3-url-signer

###Use example

var sig= require('amazon-s3-url-signer');

var bucket1 = sig.urlSigner('my key', 'my secret');
var bucket1 = sig.urlSigner('my key2', 'my secret2');

var url1 = bucket1.getUrl('GET', 'somefile.png', 'mybucket', 10); //url expires in 10 minutes
var url2 = bucket2.getUrl('PUT', '/somedir/somefile.png', 'mybucketonotheraccount', 10); //url expires in 100 minutes

###Local test

If you want to test without an s3 acount you can use https://github.com/jubos/fake-s3.

sudo apt-get install rubygems
sudo gem install fakes3  --no-rdoc --no-ri
mkdir s3_files
fakes3 -r s3_files -p 1234

Now a fakes3 server is started. Now we will generate an S3 URL, and push a file to it.

var s3 = require('./index');

var putUrl = s3.urlSigner(123, 'abc', {
  host: 'mymachine.me',
  port: 1234
}).getUrl('PUT', 'toto.json', 'my_bucket', 600);
console.log(putUrl);

The generated S3 url is:

http://mymachine.me:1234/my_bucket/toto.json?Expires=1352966881&AWSAccessKeyId=123&Signature=FDs%2Buf0hXskY1%2BUj4A7S4wHFx20%3D

Now you can use this URL with curl

curl --upload-file package.json "http://mymachine.me:1234/my_bucket/toto.json?Expires=1352966881&AWSAccessKeyId=123&Signature=FDs%2Buf0hXskY1%2BUj4A7S4wHFx20%3D"

Or with request

var fs = require('fs');
var request = require('request');
fs.createReadStream('file.json').pipe(request.put("http://mymachine.me:1234/my_bucket/toto.json?Expires=1352966881&AWSAccessKeyId=123&Signature=FDs%2Buf0hXskY1%2BUj4A7S4wHFx20%3D"))

Or with any http client you like :)

Thank to @Filirom1 for local server changes

amazon-s3-url-signer's People

Contributors

dyashkir avatar brettcvz avatar erikhazzard avatar filirom1 avatar devinfoley avatar

Watchers

JT5D avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.