I'm willing to understand the use of layers in lambdas. I'm using AWS cloud9 as IDE to sandbox the following tutorial: /
I wrote a simple function as layer lib in file logic.ts:
export function add(a: number, b: number) {
return a + b;
}
and the lambda supposed to use the above as layer in file lambdas.ts
import * as logic from '/opt/business-logic';
export const handler = async (event: any = {}): Promise<any> => {
console.log(`Addition:${logic.add(2, 3)}`);
};
folders structure in my Cloud9 workspace is:
src
├─ lambdas
│ └─ lambda.ts
└─ layers
└─ business-logic
└── logic.ts
In the import statement of lambdas.ts I got the error:
cannot find module '/opt/business-logic'
The tutorial proposed the solution to map the /opt path that is used in the deployment of lambda as storage of layer packages, into the src path by means of the tsconfig.json file:
"baseUrl": ".",
"paths": {
"/opt/business-logic": ["src/layers/business-logic/logic"],
},
but the error persists.
Someone could help?