Back to Toolbox

Miscellaneous tips & tricks

Recipes

Start a server for a folder

Run python -m SimpleHTTPServer in your project folder to make it available at http://localhost:8000.

Note: The syntax above is for the Python 2.x that comes preinstalled with macOS and Linux. The equivalent syntax for Python 3 is python -m http.server.

If you're using Node.js, you can also use the serve package, which you can run without installing with npx (it comes with recent versions of npm):

npx serve

An even simpler server is servor:

npx servor

Also take a look at budo.

Make an S3 bucket publicly available

To use a S3 bucket to keep a bunch of files and make them publicly available, you need to make a bucket policy. This is under Permissions section on the Properties tab for your bucket. Paste this into the bucket policy (myBucketName should be the name of your bucket):

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::myBucketName/*"
}
]
}

All the files inside will typically be available at http://myBucketName.s3.amazonaws.com/path/to/file but you can grab the exact URL from the Static Website Hosting section in the Properties tab.

Extra credit: This is super-useful for hosting video files, since S3 supports partial content requests which is needed to loop <video> on your web pages.