[英]Serverless framework: Serverless Error Function not found:
I'm getting started with nodejs and the serverless framwork.我开始使用 nodejs 和无服务器框架。
My handler.js contains:我的 handler.js 包含:
'use strict';
var index = require('./index.js');
module.exports.hello = async event => {
var res = await index.main();
console.log('hello');
console.log(res);
console.log('IN HANDLER');
return {
statusCode: 200,
body: JSON.stringify(
{
message: 'main function executed!',
input: event,
},
null,
2
),
};
};
My serverless.yml contains:我的 serverless.yml 包含:
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"
provider:
name: aws
runtime: nodejs12.x
region: us-east-1
# here we put the layers we want to use
layers:
# Google Chrome for AWS Lambda as a layer
# Make sure you use the latest version depending on the region
# https://github.com/shelfio/chrome-aws-lambda-layer
# - arn:us-east-1:arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:10
- arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:10
# function parameters
# you can add packaging information here
#package:
# include:
# - include-me.js
# - include-me-dir/**
# exclude:
# - exclude-me.js
# - exclude-me-dir/**
functions:
hello:
handler: handler.hello
# main:
# handler: handler.main
# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events
# Check the event documentation for details
events:
- http:
path: hello/get
method: get
my index.js:我的 index.js:
async function main(event, context, callback) {
const chromium = require('chrome-aws-lambda');
const puppeteer = require('puppeteer');
const os = require('os');
const CREDS = require('./.creds');
// exports.handler = async (event, context, callback) => {
let result = null;
let browser = null;
try {
browser = await chromium.puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: chromium.headless,
ignoreHTTPSErrors: true,
})
}
catch {
console.log('browser failed')
};
var page = await browser.newPage();
........
// })().catch(e => { console.error(e) });
};
main().catch(e => { console.error(e) });
module.exports.main = main;
When I run:当我运行时:
$ sls invoke -f hello
Serverless Error ---------------------------------------
Function not found: arn:aws:lambda:us-east-1:155754363046:function:sellthelandnow-dev-hello
The error is in the title.错误在标题中。 What am I doing wrong here?我在这里做错了什么?
Let me explain here.让我在这里解释一下。 Serverless framework can invoke(run) lambda in two ways(locally and in cloud-AWS).无服务器框架可以通过两种方式(本地和云端-AWS)调用(运行)lambda。 It seems you are trying to invoke lambda in AWS.您似乎正在尝试在 AWS 中调用 lambda。 (arn:aws:lambda:us-east-1:155754363046:function:sellthelandnow-dev-hello) Basically this arn does not exist in your AWS-155754363046 account. (arn:aws:lambda:us-east-1:155754363046:function:sellthelandnow-dev-hello)基本上这个arn在你的AWS-155754363046账户中不存在。 you need to use你需要使用
serverless deploy
to deploy lamdba to aws env.If you just want to test locally, the command is将 lamdba 部署到 aws env。如果您只想在本地测试,命令是
serverless invoke local --function functionName
So I will suggest in case you want to invoke lambda in the cloud.You need to first deploy it Or you use invoke local.所以我建议如果你想在云端调用 lambda。你需要先部署它或者你使用调用本地。
Thanks,谢谢,
Ashish阿什什
In my specific case i had this error code when i deleted the deplyed lambda function in the AWS Management Console but did not delete the Application Stack and tried to deploy the lambda function again using In my specific case i had this error code when i deleted the deplyed lambda function in the AWS Management Console but did not delete the Application Stack and tried to deploy the lambda function again using
serverless deploy
I didn't have to delete the s3 bucket - it was reused.我不必删除 s3 存储桶 - 它已被重复使用。
You can find your application stack in the AWS Management Console您可以在 AWS 管理控制台中找到您的应用程序堆栈
AWS Management Console
→ Lambda
→ Applications
AWS Management Console
→ Lambda
→ Applications
And delete并删除
AWS Management Console
→ CloudFormation
→ Stacks
AWS Management Console
→ CloudFormation
→ Stacks
An error occurred: [functionName]LambdaFunction - Resource handler returned message: "Lambda function [application stack name]-[application stage]-[lambda function name] could not be found" (RequestToken: 01010011-0111-0011-1100-001100110011, HandlerErrorCode: NotFound).发生错误:[functionName]LambdaFunction - 资源处理程序返回消息:“Lambda function [应用程序堆栈名称]-[应用程序阶段]-[lambda function 名称] 找不到”(RequestToken:010100101-001-101-01 ,处理程序错误代码:未找到)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.