I'm working with an AWS Lambda Layer called "helpers". It is written in JavaScript as an ES module. I'm trying to set up a new TypeScript project using Serverless Framework. I want to import the layer that's on the account. This is my serverless file.
service: stub
frameworkVersion: "3"
custom:
aws:
layers:
helpers:
version: 1
basePath: /stub
esbuild:
external:
- helpers
plugins:
- serverless-esbuild
// ...
functions:
hello:
handler: handler.hello
events:
- http:
path: ${self:custom.basePath}
method: get
layers:
- {layer_arn_from_custom}
my handler is:
import { createLogger } from 'helpers';
export const hello = (event) => {
const logger = createLogger();
// ...
}
Serverles-esbuild cannot tell "helpers" is a Lambda layer and cannot resolve it properly. Even though the layer is associated with the Function (confirmed in the AWS console), executing the Function results in an import error. Adding a .d.ts
file for "helpers" did not fix the problem.