A thing I made for a talk to teach people about Terraform and Infrastructure as Code.
This project exists due to a talk I'm giving (or gave, depending on the time of writing) at Node Congress. The talk is about Infrastructure as Code (IaC) and features a Node.js application that is deployed to Amazon Web Services without ever leaving the editor.
This tool is a simple lambda function that takes a given url
as input, and gives you a JPEG screenshot as output. It serves the image above, and can provide a 720p screenshot of any website of your preference at the following URL:
https://yjc4y405v8.execute-api.eu-central-1.amazonaws.com/prod?url={YOUR_URL_HERE}
This project uses Terraform to declaratively describe the infrastructure we need. Terraform then makes this real by talking to AWS via its API and creating/modifying the resources we need. Terraform also has state management, so it can make cumulative and incremental updates.
The Node.js part uses chrome-aws-lambda and puppeteer-core to spin up a headless version of Chrome, visit a website, and take a screenshot. It then returns the image represented as a Base64 string. This is wrapped in an AWS Lambda Handler and then deployed to AWS using Terraform.
It's one file that outlines the infrastructure we need (think blueprint). It then magically creates/updates this when we run terraform apply
locally.
~/.aws/credentials
.cd
into the cloned directorycd screenshooter
to open the Node.js partyarn && yarn build
cd ..
to go backterraform init && terraform apply
to put it onlineOnce it's online, you'll see URLs for dev
and prod
stages of your deployed function!
Run terraform destroy
to tear everything down.
If you'd like to talk or be friends or whatever, let's do it on twitter