HandlerNotFound 触发 aws lambda 函数

发布于 2025-01-17 18:58:19 字数 1875 浏览 1 评论 0原文

我在部署到AWS lambda功能方面有问题。当我有新消息时,我创建了一个触发器,然后我的触发器(index.receiver)处理此消息。因此,这是我的代码:

触发此功能

import receiver from "./sqs/receiver";

exports.receiver = receiver;

可以

const receiver: SQSHandler = async (event) => {
  //some logic
};

export default receiver;

之后,我在AWS CloudWatch中看到什么都没有正常工作,并给我带来了这个错误:

{
    "errorType": "Runtime.HandlerNotFound",
    "errorMessage": "index.receiver is undefined or not exported",
    "stack": [
        "Runtime.HandlerNotFound: index.receiver is undefined or not exported",
        "    at Object.module.exports.load (/var/runtime/UserFunction.js:144:11)",
        "    at Object.<anonymous> (/var/runtime/index.js:43:30)",
        "    at Module._compile (internal/modules/cjs/loader.js:999:30)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
        "    at Module.load (internal/modules/cjs/loader.js:863:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
        "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
        "    at internal/main/run_main_module.js:17:47"
    ]
}

这也是我的项目树:

.serverless
node_modules
sqs
- receiver.ts
index.ts
package.json
serverless.yml

and serverless.yml

service: some-name

provider:
  name: aws
  runtime: nodejs12.x
  region: eu-central-1
  apiGateway:
    minimumCompressionSize: 1024 # Enable gzip compression for responses > 1 KB
  environment:
    AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1
  # SQS Permission given
  iamManagedPolicies:
  - 'arn:aws:iam::aws:policy/AmazonSQSFullAccess'

functions:
  receiver:
    handler: index.receiver
    events:
      - sqs: <my-sqs-arn>

告诉我我我在做什么错?感谢您的帮助!

I have a problem with deployed to AWS Lambda function. I create an trigger to SQS queue, when I have new message then my trigger (index.receiver) processing this message. So, here is my code:

index.ts

import receiver from "./sqs/receiver";

exports.receiver = receiver;

sqs/receiver.ts

const receiver: SQSHandler = async (event) => {
  //some logic
};

export default receiver;

After trigger this function, I see in AWS CloudWatch that nothing is working correctly and throw me this error:

{
    "errorType": "Runtime.HandlerNotFound",
    "errorMessage": "index.receiver is undefined or not exported",
    "stack": [
        "Runtime.HandlerNotFound: index.receiver is undefined or not exported",
        "    at Object.module.exports.load (/var/runtime/UserFunction.js:144:11)",
        "    at Object.<anonymous> (/var/runtime/index.js:43:30)",
        "    at Module._compile (internal/modules/cjs/loader.js:999:30)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
        "    at Module.load (internal/modules/cjs/loader.js:863:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
        "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
        "    at internal/main/run_main_module.js:17:47"
    ]
}

Here is also my project tree:

.serverless
node_modules
sqs
- receiver.ts
index.ts
package.json
serverless.yml

and serverless.yml

service: some-name

provider:
  name: aws
  runtime: nodejs12.x
  region: eu-central-1
  apiGateway:
    minimumCompressionSize: 1024 # Enable gzip compression for responses > 1 KB
  environment:
    AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1
  # SQS Permission given
  iamManagedPolicies:
  - 'arn:aws:iam::aws:policy/AmazonSQSFullAccess'

functions:
  receiver:
    handler: index.receiver
    events:
      - sqs: <my-sqs-arn>

Can someone tell me what I'm doing wrong? Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑饮青盏花 2025-01-24 18:58:19

我解决了这个问题。问题是,在我的serverless.yml中,我像这样指出处理程序:处理程序:index.receiver,但是,当我们使用Typescript时,我们应该将其指向> dist/index.receiver由于AWS只能处理JS文件,因此我们还需要记住有关此功能构建项目的记忆,然后再使用> code> serverless deploy

I resolve this problem. Problem was in this, that in my serverless.yml I point handler like this: handler: index.receiver but, when we use Typescript we should point it to dist/index.receiver because AWS can handle only JS files, we also need to remember about build project with this function before using serverless deploy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文