While trying to leverage TypeScript for building Lambda functions, I encountered a roadblock when using a Lambda Layer also written in TypeScript.
The issue arises because TypeScript does not recognize the /opt/nodejs/... import path for my Layer (as it normally would in SAM or AWS). Consequently, I am unable to import the types defined in the Layer into my Lambda function.
I attempted to npm link the layer, but ran into difficulties as the import is a local path '/opt/nodejs...' rather than just a module name.
Layer:
export interface SomeType {
someField: string
}
Lambda:
import { SomeType } from '/opt/nodejs/myLayer' // this does not work
My attempts result in the error:
Cannot find module '/opt/nodejs/myLayer'.ts(2307)
. To proceed, I have to suppress this with // @ts-ignore can be ignored as this is a Lambda layer
, but this means I lose access to the TypeScript types provided by the layer.