npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

awssign

v0.0.6

Published

Creates nessasary HTTP headers for request to the AWS API. Uses AWS4-HMAC-SHA256

Downloads

4

Readme

awssign

Creates nessasary HTTP headers for request to the AWS API. Uses AWS4-HMAC-SHA256.

Given the options object to be passed to https.request(options, callback) awssign ands the following headers x-amz-date, x-amz-content-sha256 and authorization.

Credentials and region will be looked for in environment variables and secondary in ~/.aws/credentials and ~/.aws.config. For IAM Role see below.

Install

npm install awssign

Usage

var https = require('https')
var crypto = require('crypto')
var fs = require('fs')
var awssign = require('awssign')

var file = fs.readFileSync('path-to-file.txt')
var filehash = crypto.createHash('sha256').update(file).digest('hex')

var options = {
	hostname: 'mybucket.s3.amazonaws.com',
	port: 443,
	path: '/myfolder/file.txt',
	method: 'PUT',
	headers: {
		'Content-Type': 'text/plain; charset=utf8',
		'Content-Length': file.length
	}
}

awssign.signature(options, filehash) // This and nessary headers to the options object.

var req = https.request(options, function(res) {
	if (res.statusCode !== 200) {
		res.setEncoding('utf8')
		var body = ''
		res.on('data', function(chunk) { body += chunk })
		res.on('end', function() { console.error('HTTP response: %s', body)})
	}
})
req.on('error', function(err) {
	console.error('ERROR: %s', err)
})
req.write(file)
req.end()

If the HTTP request to AWS has no body call awssign.singature with only the options argument.

More options

Credentials and region can be overwritten with

awssign.setup(aws_key, aws_secret, aws_region)

Pass null for values not to be overridden.

IAM Role

If awssign is used from an EC2 instance with an IAM Role is can get the credentials from there. Just remember to set the IAM role and the S3 region.

awssign.setup(null, null, region)

awssign.iamrole(iam_role, function(err, res) {
    awssign.signature(options, bodyhash)
    var req = https.request(options, function(res) {
        ...
    })
})

License

MIT