hugo-lambda enables running static website generator Hugo inside AWS Lambda.
The repo includes the following contents:
app- Lambda's Python code.
demo_site- demo Hugo site you can use for testing.
template.yml- AWS SAM template that deploys the app to AWS
deploy_template.sh- shell script that packages dependencies and deploys the SAM template
- Read my blog post How to build a Hugo website in AWS Lambda and deploy it to S3 to understand the concepts.
- Follow steps 1, 2 and 3 to obtain dependencies:
AWS CLIpackaged with all of its dependencies. These dependencies are not included in this repository to avoid licensing issues. You can download pre-packaged layers using links in my blog post.
- Place zipped files from the previous step in directory
- Install AWS CLI:
pip install awscliand configure it.
2. Edit deployment template
chmod u+x deploy.shto set the execution permissions.
deploy.shin a text editor and make the following changes:
BUCKETNAMEwith the name of an S3 bucket that will be used for temporary storage of layers and Lambda's code.
export HUGO_LAYER_FILE_NAME=lambda-layer-hugo-0.54.zipchange the name of the zip file to whatever you named your
export LIBSTDC_LAYER_FILE_NAME=lambda-layer-libstdc.zipchange the name of the zip file to whatever you named your
export AWSCLI_LAYER_FILE_NAME=lambda-layer-awscli-1.16.115.zipchange the name of the zip file to whatever you named your
./deploy.shfrom the command line.
- If the deployment is successful, you should see outputs in the JSON format.
- Upload demo_site to the S3 bucket listed under
aws s3 sync demo_site s3://SOURCE_BUCKET_NAME.
- Invoke API Gateway endpoint listed under
BuildApiin outputs. It should look like
https://abcdefghij.execute-api.us-east-1.amazonaws.com/Prod/build/. Copy the link and open it in a browser. It will take a few seconds to run due to a Lambda cold start. When the build completes, the page will show
- Open the URL listed under
WebsiteS3BucketURLin a browser. You should see a test site titled
My New Hugo Site.