OG
This is the lambda function that generates the Open Graph image for the token.
Overview
The lambdas/og/ is an AWS Lambda@Edge function designed to dynamically generate Open Graph images for tokens. It leverages the @token-kit/og package to create these images on-the-fly, providing a visual representation of tokens for social media sharing and link previews.
Build
To set up the lambda function, follow these steps:
-
Install dependencies:
pnpm i -
Build the project:
pnpm build -
Package the lambda function:
pnpm package
This process will generate a token-kit-og-lambda.zip file that can be uploaded to AWS Lambda.
Deploy
To deploy the lambda function, follow these steps:
- Create a new AWS Lambda function in us-east-1 using the
token-kit-og-lambda.zipfile generated in the previous step. - Set the property permissions to AWS Lambda Basic Execution Role (with S3 access).
- Publish to your CloudFront Origin request function associations.
For more informations about Lambda@Edge, please follow the document Customize at the edge with Lambda@Edge
How it works
Request ----> [CloudFront] [Lambda@Edge] <--- S3 (original html <body>)
Response <---- ^----- @token-kit/og (html <head>)The Lambda@Edge function will merge the original html <body> from S3 with the html <head> from the @token-kit/og package response.
Since Lambda@Edge cannot get the response from the origin (See: Work with requests and responses), so we read the original html from S3 and replace the <head> with the <head> from the @token-kit/og package response.
We expect you use S3 + CloudFront to serve your static files with SPA. If your static files structure is different, you may need to modify the code.
And we expect the URL parameters are:
chainId(number): the chainId of the network, like 1, 137, and so oncontract(string): the contract address of the token (0x....)tokenId(number): the tokenId of the token
Full request URL example: https://example.com/?chainId=1&contract=0x1234567890123456789012345678901234567890&tokenId=1