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 AWSdeploy_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:
hugobinary,libstdc++library andAWS 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
layers. - Install AWS CLI:
pip install awscliand configure it.
- Copy
deploy_template.shtodeploy.sh. - Execute
chmod u+x deploy.shto set the execution permissions. - Open
deploy.shin a text editor and make the following changes:- In
export SOURCE_CODE_BUCKET=BUCKETNAMEreplaceBUCKETNAMEwith the name of an S3 bucket that will be used for temporary storage of layers and Lambda's code. - In
export HUGO_LAYER_FILE_NAME=lambda-layer-hugo-0.54.zipchange the name of the zip file to whatever you named yourhugolayer. - In
export LIBSTDC_LAYER_FILE_NAME=lambda-layer-libstdc.zipchange the name of the zip file to whatever you named yourlibstdc++layer. - In
export AWSCLI_LAYER_FILE_NAME=lambda-layer-awscli-1.16.115.zipchange the name of the zip file to whatever you named yourAWS CLIlayer.
- In
- Execute
./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
SourceS3Bucketin outputs:aws s3 sync demo_site s3://SOURCE_BUCKET_NAME. - Invoke API Gateway endpoint listed under
BuildApiin outputs. It should look likehttps://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 showBuild complete. - Open the URL listed under
WebsiteS3BucketURLin a browser. You should see a test site titledMy New Hugo Site.