January 18, 2024

Static Serverless Ghost

I've been running Ghost as a CMS for this blog since 2017, so almost 7 years now. I've written a number of posts about how ghost is setup. Over time, I've used different technologies as a way to learn. I started out running ghost on a single EC2 instance, then added auto-scaling behind a load-balancer, then ran it as a container in ECS. But all along, I still had some operational burden: managing the instance, cleaning out disk space, checking logs if something went wrong, etc. I'm a big fan of serverless, specifically due to the lower operational burden, so I spent some time trying to get ghost running on AWS Serverless.

Ghost on Lambda

I started with serverless-ghost, (using my fork with some changes), which runs the entire ghost in a single AWS Lambda function deployed as a ZIP file. There are some functionality limitations, but it worked well enough for me. Quite interestingly,  it copies the source code from ghost, and makes a small change to cater for the Lambda handler.  Because its running as a Zip file, its limited to a size of 250MB, which means you need to delete some files to keep within the limit. It would be better to switch to use the Lambda container image deployment, which has a much bigger size limit of 10GB.

Ghost as a static site

However, I was after an even lower operational burden, and static sites gives that level of simplicity. ghost-static-site-generator is a simple tool that creates static files, that can then be served from an S3 bucket. I chose to use this template that creates a Cloudfront distribution in front of an S3 bucket, and creates ACM certs as well.

To publish a new post, or make any change to the static site is quite simple. I push to github, where Actions runs that uploads to S3, and creates an CloudFront invalidation to refresh the site.

So now I have a static home page as well as ghost served from S3, with links to some other serverless app running on Lambda.