无服务器框架:找不到无服务器错误函数:
Serverless framework: Serverless Error Function not found:
我正在开始使用 nodejs 和无服务器框架。
我的 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
),
};
};
我的 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
我的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;
当我 运行 :
$ sls invoke -f hello
Serverless Error ---------------------------------------
Function not found: arn:aws:lambda:us-east-1:155754363046:function:sellthelandnow-dev-hello
错误在标题中。我在这里做错了什么?
让我在这里解释一下。无服务器框架可以通过两种方式(本地和云-AWS)调用(运行)lambda。
您似乎正试图在 AWS 中调用 lambda。 (arn:aws:lambda:us-east-1:155754363046:function:sellthelandnow-dev-hello) 基本上这个 arn 在你的 AWS-155754363046 账户中不存在。你需要使用
serverless deploy
将lamdba部署到aws env.If你只是想在本地测试,命令是
serverless invoke local --function functionName
所以我会建议如果你想在 cloud.You 中调用 lambda 需要先部署它或者你使用调用本地。
谢谢,
阿希什
在我的具体情况下,当我我删除了 AWS 管理控制台中已部署的 lambda 函数但没有删除应用程序堆栈 并尝试使用
再次部署 lambda 函数
serverless deploy
您必须删除应用程序堆栈,并确保为您的 lambda 删除 IAM 执行角色。
附加信息
我不必删除 s3 存储桶 - 它已被重新使用。
您可以在 AWS 管理控制台中找到您的应用程序堆栈
AWS Management Console
→Lambda
→Applications
并删除
AWS Management Console
→CloudFormation
→Stacks
- 如果删除失败,系统可能会提示您保留相关资源(IAM 角色和 s3 存储桶)
- 选择保留资源,之后手动删除
错误信息
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).
我正在开始使用 nodejs 和无服务器框架。
我的 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
),
};
};
我的 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
我的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;
当我 运行 :
$ sls invoke -f hello
Serverless Error ---------------------------------------
Function not found: arn:aws:lambda:us-east-1:155754363046:function:sellthelandnow-dev-hello
错误在标题中。我在这里做错了什么?
让我在这里解释一下。无服务器框架可以通过两种方式(本地和云-AWS)调用(运行)lambda。 您似乎正试图在 AWS 中调用 lambda。 (arn:aws:lambda:us-east-1:155754363046:function:sellthelandnow-dev-hello) 基本上这个 arn 在你的 AWS-155754363046 账户中不存在。你需要使用
serverless deploy
将lamdba部署到aws env.If你只是想在本地测试,命令是
serverless invoke local --function functionName
所以我会建议如果你想在 cloud.You 中调用 lambda 需要先部署它或者你使用调用本地。
谢谢,
阿希什
在我的具体情况下,当我我删除了 AWS 管理控制台中已部署的 lambda 函数但没有删除应用程序堆栈 并尝试使用
再次部署 lambda 函数serverless deploy
您必须删除应用程序堆栈,并确保为您的 lambda 删除 IAM 执行角色。
附加信息
我不必删除 s3 存储桶 - 它已被重新使用。
您可以在 AWS 管理控制台中找到您的应用程序堆栈
AWS Management Console
→Lambda
→Applications
并删除
AWS Management Console
→CloudFormation
→Stacks
- 如果删除失败,系统可能会提示您保留相关资源(IAM 角色和 s3 存储桶)
- 选择保留资源,之后手动删除
错误信息
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).