Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

AWS Signature Version 4 for node.js and browser.

License

NotificationsYou must be signed in to change notification settings

yugasun/aws4-sign

Repository files navigation

Build StatusDownloadsVersion

AWS Signature Version 4 for node.js and browser.

Notice: this project is rewrote fromaws4 byES6 for using on demand.

Installation

npm install aws4-sign --save# oryarn add aws4-sign

Example

Use in browser

<scriptsrc="https://unpkg.com/aws4-sign"></script><script>varsigs=Aws4Sign.sign({service:'s3',path:'/../../whatever?X-Amz-Expires=1234',signQuery:true,},{accessKeyId:'a',secretAccessKey:'b'},);</script>

Use in Node.js

consthttp=require('http');const{ sign, RequestSigner}=require('aws4-sign');constopts={host:'sqs.us-east-1.amazonaws.com',path:'/?Action=ListQueues',};// assumes AWS credentials are available in process.envsign(opts,{accessKeyId:'<your-access-key-id>',secretAccessKey:'<your-secret-access-key>',});console.log(opts);/*{  host: 'sqs.us-east-1.amazonaws.com',  path: '/?Action=ListQueues',  headers: {    Host: 'sqs.us-east-1.amazonaws.com',    'X-Amz-Date': '20121226T061030Z',    Authorization: 'AWS4-HMAC-SHA256 Credential=ABCDEF/20121226/us-east-1/sqs/aws4_request, ...'  }}*/// we can now use this to query AWS using the standard node.js http APIhttp.request(opts,function(res){res.pipe(process.stdout);}).end();// Generate CodeCommit Git access passwordconstsigner=newRequestSigner({service:'codecommit',host:'git-codecommit.us-east-1.amazonaws.com',method:'GIT',path:'/v1/repos/MyAwesomeRepo',});constpassword=signer.getDateTime()+'Z'+signer.signature();

API

aws4.sign(requestOptions, [credentials])

This calculates and populates theAuthorization header ofrequestOptions,and any other necessary AWS headers and/or request options. ReturnsrequestOptions as a convenience for chaining.

requestOptions is an object holding the same options that the node.jshttp.requestfunction takes.

The following properties ofrequestOptions are used in the signing orpopulated if they don't already exist:

namedefault
hostname/hostwill be determined fromservice andregion
methodGET
path/
body''
servicewill be calculated fromhostname orhost
region'us-east-1'
domain'amazonaws.com'
headers['Host']will usehostname orhost or be calculated if not given
headers['Content-Type']'application/x-www-form-urlencoded; charset=utf-8'
headers['Date']new Date()

Your AWS credentials (which can be found in yourAWS console) can bespecified in one of two ways:

credentials

You can configcredentials, like below:

aws4.sign(requestOptions,{secretAccessKey:'<your-secret-access-key>',accessKeyId:'<your-access-key-id>',sessionToken:'<your-session-token>',});

Or you can attach them toprocess.env usingdotenv, create.env file in your projectroot, then put below code before you use aws4 sign

require('dotenv').config();

ThesessionToken property andAWS_SESSION_TOKEN environment constiable areoptional for signing withIAM STS temporary credentials.

LICENSE

@yugasun

About

AWS Signature Version 4 for node.js and browser.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp