HandlerNotFound 触发 aws lambda 函数
我在部署到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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了这个问题。问题是,在我的
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 todist/index.receiver
because AWS can handle only JS files, we also need to remember about build project with this function before usingserverless deploy
.