• Stars
    star
    390
  • Rank 109,578 (Top 3 %)
  • Language
    CSS
  • License
    GNU Affero Genera...
  • Created over 9 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Use AWS Lambda to run the Hugo static site generator

hugo-lambda

A wrapper around the hugo static site generator to have it run in AWS Lambda whenever new (markdown or other) content is uploaded. See a tutorial here.

Project status

forthebadge forthebadge

Basic functionality checklist

  • CloudFormation template for IAM roles and buckets
  • Diagnostic/debug functionality for functions
  • Figure out a good place to store configuration
  • Download site sources to lambda instance
  • Run hugo
  • upload output to configured bucket

Advanced functionality checklist

  • CloudFormation template to set up cross-domain IAM auth
  • CloudFormation conditions for users who don't want to use Route53
  • in-browser markdown editor
  • SNS cancellation for in-progress jobs to reduce redundant hugo runs

Overview

  1. Download this repo and run the CloudFormation template
  2. Open the Lambda function in the console and add an SNS event handler from the SiteChangeTopic queue
  3. Upload your site's source to the input.your.site bucket
  4. Generated site is synced to the your.site bucket, and is served by S3 static hosting

So why go to all this trouble? Because running a CMS like Wordpress, Drupal, and others gets expensive for infrequently edited sites. You pay 24/7 to run all the code to let you edit your site, when that code only runs when you update your blog. Static site generators are cheaper to run (just toss the files somewhere) but if you're not at the computer you normally use to edit and publish content, you may not have all your tools.

hugo-lambda solves this by adding a JS editor to your hugo site, which uploads raw markdown to S3 where lambda regenerates your site. All the niceties of a CMS, but without running a server.

Quickstart

To start, you'll need to have GNU make, awscli, PyYAML, and npm installed.

  1. Clone this repo git clone https://github.com/ryansb/hugo-lambda
  2. Replace "input.rsb.io" with your input bucket in generate/config.yml
  3. Replace "rsb.io" with your own domain in template.yml This must be the root of a Route53 domain you control, and an available bucket name.
  4. Create the function and roles by running make create
  5. Upload all your content to input.yourdomain.com
  6. Enjoy!

If you'd just like to try it out, the "demo-site" directory in this repository contains a hugo site with a single post that will work. The theme is liquorice, distributed under the terms of the MIT license. To use it, upload the full contents of demo-site to the input.yourdomain.com S3 bucket.

How it works

See these blog posts for more info on using/deploying hugo-lambda

Lambda is a service that lets you define a node.js function and have it run whenever a specific trigger happens. These triggers can be new objects in S3, events in a Kinesis stream, or DynamoDB table updates. Those functions can access other buckets, download files, or do just about anything else. The kicker is you only pay for the time your function is running. Instead of paying for an instance 24/7 to react to events, you only pay for the time spent actually reacting. This makes lambda incredibly cheap for cases where you have an infrequent event that requires some action to happen.

There are two buckets where content resides. The first is input.yoursite.com, which contains all the information hugo needs to generate your site. The second is the website bucket that holds the finished site and serves it to the world.

Developing

When working on the functions, you can manually zip the code (with dependencies) and upload it to the Lambda console.

CloudFormation

Ok, that CFN template is pretty large/gross. To make it easier to manage and edit, I've moved to editing it in YAML and generating the JSON version to send to AWS. If you edit the YAML, you can regenerate the JSON template one of two ways.

  1. Make sure the PyYAML module is installed and run make template
  2. Use a site like yamltojson.com

To use it, you'll need to provide the base domain of your site. For example, mine is rsb.io. This will determine the name of your buckets and will make the correct Route53 aliases to make your site accessible.

Right now, the following resources are created by the template

  1. 3 buckets: input.ROOT, www.ROOT, and ROOT
  2. 2 domain records: one for your apex and one for www.ROOT, which redirects to ROOT via the www.ROOT bucket.
  3. ExecRole IAM Role. The ExecRole is the role that the lambda functions take on when they execute. Thi role gets access to the S3 buckets to upload and download content.
  4. SiteChangeTopic SNS queue, because CloudFormation can't set up bucket notifications to Lambda directly.

Troubleshooting - Oops, my stack failed!

The most common problem you'll hit is probably not having a Route53 record set for your domain. The stack won't create one, so it'll fail instead. To get around this you can just delete the "SiteDNS" resource. Nothing depends on it, so no worries.

The next one will probably be IAM problems. If this happens, make sure you have the permissions to create/edit IAM roles. Typically if you aren't an administrator on your account (or are using a scoped-down IAM role yourself), you won't have the permissions to do this.

If there are problems with the function itself, you can use the awslogs tool to view the logs from your function group.

Contributing

Questions, suggestions, bug reports, and contributions are welcome as pull requests or issues on this repo. Please see the Contributor code of conduct for community guidelines.

This project is released under the GNU Affero General Public License, see LICENSE.txt for the full text of the license.

More Repositories

1

sklearn-build-lambda

Build the numpy/scipy/scikitlearn packages and strip them down to run in Lambda
Shell
207
star
2

wut4lunch_demos

Demos to accompany an article comparing the Flask, Django, and Pyramid web frameworks.
Python
180
star
3

cfn-wrapper-python

Python decorator for making Lambda-backed CloudFormation resources
Python
71
star
4

disq

Python disque client, built on redis-py
Python
53
star
5

acm-certs-cloudformation

CloudFormation resource for AWS Certificate Manager cert requests
Python
47
star
6

yesterdaytabase

Cascade data from production to staging with AWS RDS and Lambda
Python
21
star
7

hugo-shortcodes

Handy shortcodes for the http://gohugo.io/ static site generator
HTML
20
star
8

serverless-cat-facts

Distribute facts about cats without needing to run your own infrastructure
Python
20
star
9

pubkey_police

Looks for publicly-readable RSA private keys and opens an issue on that repo notifying the owner.
Python
16
star
10

gitwarrior

Interface between Git Issues and TaskWarrior
Python
15
star
11

bookmarkd

Markdown -> IPython conversion tool
Python
15
star
12

ipylogue

A git-backed store for ipython notebooks
Python
13
star
13

ofCourse

Python courseware leveraging Flask and OpenShift
HTML
12
star
14

af3ro

Afero-compliant interface to S3
Go
11
star
15

pynamodb-polymorph

Calculated/copied attributes to support advanced single-table design in DynamoDB
Python
10
star
16

workstation

Ansible scripts to configure workstations and remote boxen
Shell
9
star
17

django-zappa-example

An implementation of my favorite Django demo - wut4lunch on AWS Lambda and API Gateway
Python
8
star
18

pepbrowser

An urwid-based browser for Python Enhancement Proposals (PEPs) that works on- and off-line.
Python
6
star
19

dotfiles

Configuration files for my environment.
Python
6
star
20

gitbyatruck

Read your git repository history and track propagation of knowledge through your team.
JavaScript
6
star
21

taskforge

A workflow system to help you wield your tasks
Python
6
star
22

crop

Cloudformation'd Repeatable Operator Packages
Python
5
star
23

lambda-ssl-alerts

AWS Lambda function to alert you to expiring SSL certs
Python
4
star
24

netHUD

a.k.a. mustached octo dangerzone
Python
4
star
25

gitsniffer

Find git repos where they live. In the CLOOUUD
Python
4
star
26

lmk

A tiny Golang SNS publisher
Go
4
star
27

microchord

C
3
star
28

cornice-openshift-quickstart

Python
3
star
29

spacehub

Space. Space. Wanna go to space.
JavaScript
3
star
30

arsd

Rust
3
star
31

bison-rates-demo

Rust
3
star
32

ask-an-expert-jan-2017

Companion files to the demos on Ansible's AWS Ask an Expert webinar January 11 2017
Python
3
star
33

ask-an-expert-sept-2017

Companion files to the demos on Ansible's AWS Ask an Expert webinar on September 14th
Python
3
star
34

gofigure

Golang configurator for managing multiple sources of information about your app's runtime
Go
3
star
35

networkingnotworking

Networking that does no work!
Go
2
star
36

tremendous

A wrapper for libfab (a fabulous reimplementation in C)
C
2
star
37

zsh-boto

ZSH tab-completion for Python's AWS library, Boto
2
star
38

brassballs

2
star
39

legowebservices

Go
2
star
40

FOOD

Parser Of On-campus Preferred Specials
Python
2
star
41

vc_notify

A simple script that lets me know if my repos are pushed to, or if repos I'm watching are pushed to.
Python
2
star
42

lemon_twist

A Twisted take on that same old Drink.
Python
2
star
43

otelme

A low-friction OpenTelemetry wrapper for Python apps. It comes with sugar over basic spanning and the `tell` magic receiver
Python
2
star
44

boto-layer-optimizer

Python
1
star
45

project_euler

My work on Project Euler, figured it was worth a shot
Python
1
star
46

rocpy.org

New Iteration of the Rochester Python User Group site
JavaScript
1
star
47

ish

Impulse Shell
Python
1
star
48

livesrv

A golang app server that you can reload parts of without interrupting web requests.
Go
1
star
49

decau.se

CSS
1
star
50

mdtocs

MarkDown Table Of Contents System
Python
1
star
51

hfoss-site

Individual HFOSS site, with archival content.
Python
1
star
52

hat-market-demo

Python
1
star
53

solitaire_haskell

Haskell implementation of https://www.schneier.com/solitaire.html
Haskell
1
star
54

yolo-octo-wookie

Shell
1
star
55

wrong.js

1
star
56

double-split-named

1
star
57

hybrid-operations-demo-repo

1
star
58

heat-standalone

1
star