https://serverless-stack.com/ logo
#guide
Title
# guide
j

Jay

06/29/2021, 7:13 PM
Last week we wanted to create better social media share images for Serverless-Stack.com. We wanted to generate them dynamically. So we decided to build this in serverless using SST! The entire thing is publicly available on GitHub (https://github.com/serverless-stack/social-cards). We also added a chapter going over the details of how we built it and how it integrates with our static sites. The gist of it is that we create HTML templates that are loaded locally in a Lambda function. It takes screenshots of these using Puppeteer and caches it in S3. We also add CloudFront in front of it with a custom domain. Check out all the details here. https://serverless-stack.com/chapters/dynamically-generate-social-share-images-with-serverless.html
a

Adrián Mouly

06/29/2021, 7:48 PM
So it’s generated in runtime or once and cached?
j

Jay

06/29/2021, 7:49 PM
Yeah generated on the first request and cached from that point on.
a

Adrián Mouly

06/29/2021, 8:10 PM
But how it knows when to generate it?
j

Jay

06/29/2021, 9:29 PM
There’s a meta tag on our webpages, that Twitter/FB/etc. will hit when you share the URL. That’s what triggers generating the image.
a

Adrián Mouly

06/29/2021, 9:30 PM
I see.
But how we know when to get from cache and when not?
j

Jay

06/29/2021, 9:30 PM
We take the request URL and convert it into an S3 key, then check if that key exists in S3.
a

Adrián Mouly

06/29/2021, 9:31 PM
Ohhh nice.
j

Jay

06/29/2021, 9:31 PM
Yeah and a CloudFront distribution in front of it all.
a

Adrián Mouly

06/29/2021, 9:31 PM
Yeah cdn makes sense.
a

Alex Price

06/30/2021, 7:24 AM
For those who want a hosted solution my mate runs this: https://ogimpact.sh/
j

justindra

07/01/2021, 4:52 AM
Would you at some point move the AWS Chrome Layer into the SST config instead of hardcoding it?
j

Jay

07/10/2021, 12:57 AM
@justindra Sorry I missed this. What do you mean by moving into the SST config?
j

justindra

07/10/2021, 12:58 AM
All good @Jay! I mean would we be able to define these installable lambda layers through SST/Cdk instead of hardcoding an arn.
I'm assuming future state that is
j

Jay

07/10/2021, 2:33 AM
Interesting, so being able to specify them by name instead of their ARN?
j

justindra

07/12/2021, 11:15 PM
Yep exactly. I think that would be a lot more re-deployable when creating new environments etc.
j

Jay

07/13/2021, 5:57 PM
cc @Frank
3 Views