Query parameters:
- inline: inline latex string
- block: block latex string
- color: color of the rendered image
- alternativeColor: alternative color of the rendered image (dark mode)
esbuild produces one JavaScript file with all dependencies. This is the only file that you need to add to the .zip archive.
Steps:
- Create a new Lambda function on aws console, function name:
math-renderer
- Run
yarn install & yarn build
, upload dist/index.zip file to lambda function - Set the handler to
index.handler
- Set the runtime to
Node.js 18.x
- Select configuration tab, create a function URL
Done!
You can use AWS Codebuild to build and deploy the function.
- Create a new Codebuild project, project name:
math-renderer
- Set the source to
https://github.com/hackertalk/math-renderer
- Set the buildspec to
buildspec.yml
- Set the environment to
Managed image
, operating system:Ubuntu
, runtime:Standard
, image:aws/codebuild/standard:6.0
, environment type:Linux
- Select
New service role
, role name:codebuild-math-renderer-service-role
After creating the project, open IAM console, find the role codebuild-math-renderer-service-role
,
attach the policy AWSLambdaFullAccess
to it.
Or you can create a new policy and attach it to the role.
Required permissions:
actions: lambda:UpdateFunctionCode
, lambda:UpdateFunctionConfiguration
Resource: arn:aws:lambda:my-region:my-aws-account-id:function:math-renderer
- Change runtime handler to
index.edgeHandler
on aws console - Create a new CloudFront distribution for the Lambda@Edge function
- Set the origin to function url
- Create a new cache policy, cache all query strings (best practice) and select the cache policy for the distribution