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

s3-upload-static

v0.1.0

Published

Allows you to upload static files to S3 buckets.

Downloads

5

Readme

Deploy static sites to Amazon S3 using Node!

  • Uploads are fast (only changed files are sent).
  • Old files (or files that no longer match the set of patterns) are deleted. Easily remove accidental uploads by simply changing the configuration and redeploying.
  • Configuration uses Ant Glob syntax. Easy to understand and update.
module.exports = {
	credentials:"aws-credentials.json",
	bucketName:"example.com",
	patterns:[
		"scripts/*.js",
		"stylesheets/default.css",
		"images/**/*.jpg",
		"index.html"
	]
}

Install via npm: npm install -g s3-upload

S3 Bucket Setup

Create a bucket

Log into your AWS S3 console and create a new bucket for your site.

Bucket names must conform with DNS requirements:

  • Should not contain uppercase characters
  • Should not contain underscores
  • Should be between 3 and 63 characters long
  • Should not end with a dash
  • Cannot contain two, adjacent periods
  • Cannot contain dashes next to periods (e.g., "my-.bucket.com" and "my.-bucket" are invalid)

Configure the Bucket Static Website Hosting

Once the bucket is created, select it and choose Properties > Static Website Hosting.

Choose proper values for the Index Document and Error Document fields (i.e. index.html and 404.html).

The Index Document is searched for relative to the requested folder: http://my.aws.site.com/some/subfolder/ becomes http://my.aws.site.com/some/subfolder/index.html.

The Error Document path is always relative to the root of the site. All errors are redirected to http://my.aws.site.com/404.html.

Configure a Public Readable Policy for the Bucket

Static sites hosted on S3 do not support private files (password protection, etc). You must make all files publicly accessible. From your buckets Properties page, choose Permissions > Edit/Add bucket policy. Copy and past the policy below (replace YOUR-BUCKET-NAME for the bucketName you created previously)

{
	"Version": "2008-10-17",
	"Statement": [
		{
			"Sid": "PublicReadForGetBucketObjects",
			"Effect": "Allow",
			"Principal": {
				"AWS": "*"
			},
			"Action": "s3:GetObject",
			"Resource": "arn:aws:s3:::YOUR-BUCKET-NAME/*"
		}
	]
}

S3 User Setup

Log into your AWS Console and go to the Users management console. Click the Create New Users button and enter a username.

Credentials File

Have AWS create a new key pair for the user and copy the contents into a aws-credentials.json file in the root directory of your project. You should add this file to .gitignore (or similar) so that credentials are not checked into version control.

{ 
	"accessKeyId": "PUBLIC_KEY", 
	"secretAccessKey": "SECRET_KEY", 
	"region": "us-west-2" 
}

note: As AWS SDK's documentation points out, you could also set those as AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables

User Permissions

From the AWS IAM Users Console select the newly created user, then the Permissions Tab, then click the Attach User Policy button. Paste in the following (substituting BUCKET-NAME as appropriate).

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "s3:DeleteObject",
        "s3:PutObject",
        "s3:ListBucket"
      ],
      "Sid": "AllowNewUserAccessToMyBucket",
      "Resource": [
        "arn:aws:s3:::BUCKET-NAME",
		"arn:aws:s3:::BUCKET-NAME/*"
      ],
      "Effect": "Allow"
    }
  ]
}

Create Config

Create a file called aws-upload.conf.js in the root directory of your project and copy and paste in the code below. Modify bucketName and the patterns array as appropriate for your project. All patterns are evaluated with the current directory as root, and the bucket directory structure will mirror the local one.

module.exports = {
	credentials:"aws-credentials.json",
	bucketName:"example.com",
	patterns:[
		"scripts/*.js",
		"stylesheets/default.css",
		"images/**/*.jpg",
		"index.html"
	]
}

Upload!

Simply call s3-upload from the same directory as your config file, and the upload will happen.