I have a NodeJS AWS Lambda function which generates an e-mail based on a html template file (emailTemplate.html
). I started building my lambdas with esbuild via SAM. Now I wonder how I can configure SAM/esbuild to include this file into my lambda package.
This is the SAM template configuration for the lambda:
EmailNotificationFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./lambdas-node/email-notifications/
Handler: daily-summary.handler
Timeout: 120
MemorySize: 512
Runtime: nodejs16.x
Metadata:
BuildMethod: esbuild
BuildProperties:
Sourcemap: true
EntryPoints:
- daily-summary.ts
In my application code, I read the file from the local file system:
fs.readFileSync("./emailTemplate.html", "utf-8")
The html file is small so I'd like to stick to this minimalistic approach. I can always fetch the file from S3 or package it in a layer but I prefer not to go there.