首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在aws lambda上部署Laravel facade问题

在aws lambda上部署Laravel facade问题
EN

Stack Overflow用户
提问于 2021-03-17 07:30:25
回答 2查看 654关注 0票数 0

我用拉拉8和布雷夫把它部署在兰达。在做了一个cron作业函数后,发送电子邮件。当我部署它时,它的外观有一个问题

代码语言:javascript
复制
{
  "errorType": "RuntimeException",
  "errorMessage": "A facade root has not been set.",
  "stackTrace": [
    "#0 /var/task/app/functions/sendTestMail.php(11): Illuminate\\Support\\Facades\\Facade::__callStatic()",
    "#1 /var/task/vendor/bref/bref/src/Runtime/Invoker.php(34): Bref\\Runtime\\FileHandlerLocator->App\\Functions\\{closure}()",
    "#2 /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php(102): Bref\\Runtime\\Invoker->invoke()",
    "#3 /opt/bref/bootstrap.php(43): Bref\\Runtime\\LambdaRuntime->processNextEvent()",
    "#4 {main}"
  ]
}

这是我的目录结构和函数:sendTestMail.php

serverless.yml:

代码语言:javascript
复制
service: test
provider:
  name: aws
  # The AWS region in which to deploy (us-east-1 is the default)
  region: ap-southeast-1
  # The stage of the application, e.g. dev, production, staging… ('dev' is the default)
  stage: dev
  runtime: provided.al2

package:
  # Directories to exclude from deployment
  exclude:
    - node_modules/**
    - public/storage
    - resources/assets/**
    - storage/**
    - tests/**

functions:
  # This function runs the Laravel website/API
  web:
    handler: public/index.php
    timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
    layers:
      - ${bref:layer.php-80-fpm}
    events:
      - httpApi: "*"
  # This function lets us run artisan commands in Lambda
  artisan:
    handler: artisan
    timeout: 120 # in seconds
    layers:
      - ${bref:layer.php-80} # PHP
      - ${bref:layer.console} # The "console" layer
  cron:
    handler: app/functions/sendTestMail.php
    layers:
      - ${bref:layer.php-80}
    events:
      - schedule: rate(5 minutes)

plugins:
  # We need to include the Bref plugin
  - ./vendor/bref/bref

有人知道如何解决这个问题吗?顺便说一句,在部署之前,我如何在本地机器上测试处理程序函数?谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-03-18 23:07:25

我认为这是由于web函数中的处理程序是public/index.php的问题造成的。这正确地初始化了Laravel应用程序。您的cron函数处理程序是app/function/sendTestMail.php,因此永远不会调用index.php,而Laravel内核也不会处理请求。

我目前还没有一个很好的解决方案,因为我觉得这违反了很多在Laravel的最佳实践和规则,我想尝试更多。但我能够获取整个index.php内容,并将其粘贴到Lambda正在调用的文件中的返回函数之上。

换句话说,我认为如果你粘贴这个

代码语言:javascript
复制
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

use App\Models\Task;
define('LARAVEL_START', microtime(true));
if (file_exists(__DIR__.'/storage/framework/maintenance.php')) {
    require __DIR__.'/storage/framework/maintenance.php';
}
require __DIR__.'/vendor/autoload.php';

$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Kernel::class);

$response = tap($kernel->handle(
    $request = Request::capture()
))->send();

$kernel->terminate($request, $response);

作为应用程序/functions/sendTestMail.php文件中的第一件事,它可能会工作。这取决于您在中间件中编码的内容,因为它将首先运行。

这在我的申请中对我起了作用。

票数 0
EN

Stack Overflow用户

发布于 2021-03-17 08:20:09

您可以尝试这个错误。

  • config:cache
  • 配置:清除
  • php手工缓存:清除
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66668691

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档