簡體   English   中英

無服務器框架:未找到無服務器錯誤 Function:

[英]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。如果您只想在本地測試,命令是

serverless invoke local --function functionName

所以我建議如果你想在雲端調用 lambda。你需要先部署它或者你使用調用本地。

謝謝,

阿什什

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

您必須刪除應用程序堆棧,並確保刪除 lambda 的 IAM 執行角色。


附加信息

我不必刪除 s3 存儲桶 - 它已被重復使用。

您可以在 AWS 管理控制台中找到您的應用程序堆棧

  • AWS Management ConsoleLambdaApplications

並刪除

  • AWS Management ConsoleCloudFormationStacks
  • 如果刪除失敗,系統可能會提示您保留關聯資源(IAM 角色和 s3 存儲桶)
  • 選擇保留資源並在之后手動刪除它們

錯誤信息

發生錯誤:[functionName]LambdaFunction - 資源處理程序返回消息:“Lambda function [應用程序堆棧名稱]-[應用程序階段]-[lambda function 名稱] 找不到”(RequestToken:010100101-001-101-01 ,處理程序錯誤代碼:未找到)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM