Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 无服务器框架:未找到无服务器错误函数:_Node.js_Serverless Framework - Fatal编程技术网

Node.js 无服务器框架:未找到无服务器错误函数:

Node.js 无服务器框架:未找到无服务器错误函数:,node.js,serverless-framework,Node.js,Serverless Framework,我开始使用nodejs和无服务器框架 My 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 {

我开始使用nodejs和无服务器框架

My 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
    ),
  };


};
# 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 serverless.yml包含:

'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
    ),
  };


};
# 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:

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

错误在标题中。我做错了什么?让我在这里解释一下。无服务器框架可以通过两种方式(本地和云中)调用(运行)lambda。 似乎您正试图在AWS中调用lambda。(arn:aws:lambda:us-east-1:155754363046:function:sellthelandnow dev hello)基本上,此arn不存在于您的aws-155754363046帐户中。你需要使用

serverless deploy
将lamdba部署到aws env。如果您只想在本地进行测试,则命令为

serverless invoke local --function functionName
因此,我建议您在云中调用lambda,您需要首先部署它或使用invoke local

谢谢


Ashish

什么是
sellthelandnow开发人员您好
?我不会在代码中的任何地方使用它。非常感谢!