Laravel 5 Laravel命令在AWS EC2上由Cron执行时返回不同的输出

Laravel 5 Laravel命令在AWS EC2上由Cron执行时返回不同的输出,laravel-5,amazon-ec2,cron,amazon-elastic-beanstalk,Laravel 5,Amazon Ec2,Cron,Amazon Elastic Beanstalk,我在弹性Beanstalk环境中的EC2实例中遇到了一些cron作业问题 当我连接到EC2实例并从终端键入php artisan命令:backup_logs时,作业运行平稳,一切正常。 而当作业通过cron***/usr/bin/php/var/app/current/artisan命令运行时:backup_logs会在日志中返回以下错误: [2018-09-17 16:14:01] production.ERROR: Missing required client configuration

我在弹性Beanstalk环境中的EC2实例中遇到了一些cron作业问题

当我连接到EC2实例并从终端键入
php artisan命令:backup_logs
时,作业运行平稳,一切正常。 而当作业通过cron
***/usr/bin/php/var/app/current/artisan命令运行时:backup_logs
会在日志中返回以下错误:

[2018-09-17 16:14:01] production.ERROR: Missing required client configuration options:

region: (string)

  A "region" configuration value is required for the "s3" service

  (e.g., "us-west-2"). A list of available public regions and endpoints can be
  found at http://docs.aws.amazon.com/general/latest/gr/rande.html. {"exception":"[object] (InvalidArgumentException(code: 0): Missing required client configuration options:

region: (string)

  A \"region\" configuration value is required for the \"s3\" service
  (e.g., \"us-west-2\"). A list of available public regions and endpoints can be
  found at http://docs.aws.amazon.com/general/latest/gr/rande.html. at /var/app/current/vendor/aws/aws-sdk-php/src/ClientResolver.php:371)
[stacktrace]
#0 /var/app/current/vendor/aws/aws-sdk-php/src/ClientResolver.php(267): Aws\\ClientResolver->throwRequired(Array)
#1 /var/app/current/vendor/aws/aws-sdk-php/src/AwsClient.php(158): Aws\\ClientResolver->resolve(Array, Object(Aws\\HandlerList))
#2 /var/app/current/vendor/aws/aws-sdk-php/src/S3/S3Client.php(261): Aws\\AwsClient->__construct(Array)
#3 /var/app/current/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php(208): Aws\\S3\\S3Client->__construct(Array)
#4 /var/app/current/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php(125): Illuminate\\Filesystem\\FilesystemManager->createS3Driver(Array)
........
它在laravel.log上给出了一个
生产
错误,而这是
开发
, 并且要查找的值已设置。正如我前面提到的,当我以登录用户的身份从终端运行时,上传工作正常

我对所有命令都有同样的问题,而且当我想在计划中运行作业时,也会发生同样的错误

谁能帮我照点光?多谢各位

解决方案 因此,要解决此问题,只需在
.ebextensions
文件夹中创建一个配置文件,并粘贴以下YAML代码:

files:
  "/etc/cron.d/artisan_scheduler":
     mode: "000644"
     owner: root
     group: root
     content: |
       * * * * * ec2-user . $HOME/.bash_profile; php /var/app/current/artisan schedule:run >> /dev/null 2>&1

我认为S3SDK环境变量是为当前运行artisan命令的shell用户设置的(当它正常运行时)。您需要检查它需要的env变量并在cron命令前面加上它们,或者您可以尝试在cron命令中加载用户现有的变量

最流行的解决方案似乎是“来自问题”,它为您提供了在cron命令前面加上以下内容的功能:


$主页/.profile

是的,是的。我在谷歌上搜索了这么多,却找不到答案。谢谢