Domain Redirection Using Amazon S3

Setting up redirect is one of the most common tasks in web development. Whether redirecting a single page to another, or redirecting an entire domain to a new one. Knowing how to set up redirects is a basic requirement for any web developer. In this post, I’m going to show you how to set up a domain redirect with nothing more than an Amazon S3 bucket. Common Use Cases There are a lot of different use cases for redirection.

How to Make Files Uploaded to S3 Default to Public

By default, files uploaded to Amazon S3 are private, requiring a separate action to make public. To make uploads default to public, add this policy to your S3 bucket. { "Version": "2008-10-17", "Statement": [{ "Sid": "AllowPublicRead", "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": [ "s3:GetObject" ], "Resource": [ "arn:aws:s3:::MY_BUCKET_NAME/*" ] }] } If you aren’t sure how to add a policy, follow these steps: click on bucket expand the Permissions row click “Add Bucket Policy” copy/paste the snippet below into the text area.

How to Replicate a MongoDB Database from Remote to Local

Here is a simple script to backup a MongoDB remote database and restore it locally. #!/bin/bash HOST="" PORT="1337" REMOTE_DB="myremote" LOCAL_DB="mylocal" USER="giraffe" PASS="7hIs15MyPa5s" ## DUMP THE REMOTE DB echo "Dumping '$HOST:$PORT/$REMOTE_DB'..." mongodump --host $HOST:$PORT --db $REMOTE_DB -u $USER -p $PASS ## RESTORE DUMP DIRECTORY echo "Restoring to '$LOCAL_DB'..." mongorestore --db $LOCAL_DB --drop dump/$REMOTE_DB ## REMOVE DUMP FILES echo "Removing dump files..." rm -r dump echo "Done." And that’s it. Dumping and restoring MongoDB databases really is that easy.