我开始学习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错误在标题中。我在这里做错什么了?
发布于 2020-06-05 18:41:50
让我在这里解释。无服务器框架可以通过两种方式(本地和云-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,需要首先部署它,或者使用invoke local。
谢谢,
阿什
发布于 2021-10-28 07:22:40
在我的具体案例中,当删除AWS管理控制台中已部署的lambda函数时,我有这个错误代码,但是没有删除Application ,并且尝试再次部署lambda函数,使用
serverless deploy您必须删除应用程序堆栈,并确保删除lambda的IAM执行角色。
更多信息
我不需要删除s3桶-它被重用了。
您可以在AWS管理控制台中找到应用程序堆栈
AWS Management Console→Lambda→Applications和删除
删除失败时,可能会提示您保留相关资源(IAM角色和
AWS Management Console Bucket))。
错误消息
发生错误: functionNameLambdaFunction -资源处理程序返回消息:“无法找到lambda函数应用程序堆栈名称-应用程序级-lambda函数名”(RequestToken: 01010011-0111-0011-1100-001100110011,HandlerErrorCode: NotFound)。
https://stackoverflow.com/questions/62221815
复制相似问题