This post is part of a series. You’re reading Part 1.
Introduction
For those who don’t know what Hugo is, it’s a static website generator. Its source material is a Hugo template with your content in Markdown. I’ve used it for a while, in fact this blog is generated using Hugo. Hugo can give you an entire site in HTML/CSS and any required Javascript that you can then place anywhere on the web.
While that sounds fantastic, I had to run Hugo on my local machine and copy the resulting website files to my S3 bucket that hosts this blog. That’s just too manual for me and not cloudy enough.
I have my blog source material in a GitHub repo. Let’s see if there’s anything I can do with it.
Let’s step out my current process of a blog post:
- Write a blog post in Markdown.
- Add file to Git, Commit the changes and push to my remote repo in GitHub.
- Run Hugo locally to generate a new copy of my blog in HTML.
- Copy site files to my S3 bucket (drag and drop - gross)
Enter Lambda, SNS topics and GitHub service integrations…
With these 3 services you can have your GitHub source pulled by Lambda, generate your site with Hugo and written to your S3 bucket everytime a commit is made to the GitHub repo.
There are plenty of tutorials out there that cover each component separately but none that can walk through the entire process (one definitely came close though). This post will cover the creation of the SNS topic and integration with GitHub.
I’m assuming you already have an AWS account and a GitHub account with a repo you’d like to deploy from.
Configuring SNS and GitHub Integration
The first step is to get GitHub to notify AWS whenever there is a new commit. We’ll need to create an SNS topic, an IAM user and a policy so GitHub can use this user to publish to the SNS topic.
SNS Topic
- Login to the AWS console
- Open the SNS dashboard
- Click Create topic
- Give the topic a name and description.
- Once created, note the ARN. You’ll need it later.
IAM policy for the GitHub user
In the AWS console open the IAM dashboard.
Click Policies on the left.
Click Create policy along the top.
In the policy editor, select the JSON tab.
Enter the following JSON snippet for the new policy:
{ "Version": "2012-10-17", "Statement": [ { "Action": [ "sns:Publish" ], "Resource": [ "{your-SNS-topic-ARN-here}" ], "Effect": "Allow" } ] }
Click the Review policy button to continue.
Give this new policy a name and description.
Review the summary of privileges that the policy will provide.
Click Create policy when you are happy with it. Keep note of the policy name you’ll need it in the next step.
The policy you just created will Allow (the “Effect”) any attached IAM role or user to Publish (the “Action”) to the ARN specified (the “Resource”).
Next up is the IAM user.
IAM user for GitHub integration
We’ll need to create an IAM user for GitHub. The GitHub service integration needs an Access Key and a Secret Key to publish to the SNS topic.
- In the AWS console open the IAM dashboard.
- Click Users on the left.
- Click Add user along the top.
- Provide a new username and select Programmatic access for the AWS access type.
- Click Next: Permissions.
- Go to Attach existing policies directly and search for the new policy you created.
- Select the checkbox next to the policy name.
- Click Next: Review.
- Review the user name, access type and policies given. Click Create user.
- Keep a copy of the Access key ID and the Secret access key of the new user you’ve created. You’ll need them for the next step.
Enable GitHub integration to SNS
- Login to GitHub and open your repository.
- Click the Settings tab.
- Go to Integrations & services on the left.
- Using the Add service drop down, select Amazon SNS.
- Provide the AWS information required for SNS publication:
- Aws key is the IAM user Access Key from the previous step.
- Sns topic is the full ARN of the SNS topic created earlier.
- Sns region is the AWS region identifier that your SNS topic was created in. To find your region’s identifier go here.
- Aws secret is the IAM user Secret Key from the previous step.
- Click Add service.
GitHub will now publish a notification to the SNS topic whenever a new commit is made.
–
That’s it for Part 1. Part 2 is below:
- Restore of a Wordpress deployment is stuck redirecting the port
- Backups and Restores using Velero in TKGm 1.6.1
- Unable to upgrade the database: org.postgresql.util.PSQLException: ERROR: could not open shared memory segment: No such file or directory
- Upgrading Cloud Director 10.4.1 to 10.5
- Installing and Configuring Velero in TKGm 1.6.1 on vSphere