Saturday, December 17, 2016

Using AWS S3 as a Yum Repository

In an earlier post I described how you can use an S3 bucket to host a yum repository.  In this post we'll give the repository a friendlier name and create an index page that's a tad more helpful.  If you're not using AWS S3 and CloudFront to host your static assets, you might want to consider looking into this simple to use solution for running a website without having to manage a webserver.

Visit to see the final product.

If you recall from our earlier post we created a yum repository hosted by an S3 bucket by following these steps.
  1. Create a temporary directory and a noarch subdirectory
  2. Copy the rpm files to the noarch directory
  3. Create the yum repository using createrepo
  4. Sync the local directory with the S3 bucket
  5. Set public permissions for the bucket (make sure this is what you actually want to do)
The first step is to create bucket that will have the same name as the friendly repository domain name you have selected.  If you are heeding AWS' recommended best practices for naming buckets, you'll know bucket names are global and must be unique, so a good choice is to use a domain name that you own in naming buckets.  If you want S3 to serve up your bucket as a website, then name the bucket using the domain name you'll be using to access the site.  In our case that's

In order to create a website from our bucket, we'll use the AWS CLI as shown below.

$ aws s3 website s3:// --index-document=index.html

Refer back to the previous blog post to see how to sync your local repository with the S3 bucket and set the proper permissions so that the public can access the files.  Of course, make sure that you actually want to allow the public to see those files!

Using Route 53 we'll setup our domain name to point to the S3 bucket using an alias record.

On the AWS console, select Route 53, then proceed to Hosted Zones and select the domain that will host your site.
Select your hosted zone

Click on the "Goto Record Sets" button.

Now click on the "Create Record Set" button to create an entry for your repo.

Create a new entry
At this point we need to add  a new DNS entry, however instead of using an IP address, we'll use an alias to point our name to the S3 hosted website.

Enter the sub-domain name of your website and select "Alias".  Move to the field labled "Alias Target".  Your bucket should appear in the drop down if you have named the bucket correctly.

Select the bucket then click the "Create Record Set" button to complete the process.   Visit your website!

If you run into issues, make sure you check out the previous blog and follow the steps to create your bucket and set the permissions.

For our Bedrock yum repository, we've create a spartan but useful index page that contains all you should need to install Bedrock from our repo.

Thanks AWS!

Being able to use S3 to host your static assets is not restricted to just a yum repository.  You can create an entire web application, hosted by S3 buckets without the need to run a web server.  You can even use AWS Lambda functions to create the dynamic portions of your website.

Aside from not having to provision and pay for an EC2 instance to run a webserver, AWS provides some basic levels of protection now against DDoS and other common website attacks.  Consider using S3 buckets to host your static assets.  If you need better performance, look at CloudFront, AWS' CDN solution.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.