最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

AWS Lambda with Layer in ts cannot find module in optfolder - Stack Overflow

programmeradmin1浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论