Any DevOps wiz in here?
Laravel Command returning different output when executed by Cron on AWS EC2
Hello guys, I'm having some trouble with the cron jobs in a EC2 instance on a Elastic Beanstalk environment.
When I connect to the EC2 instance and I type php artisan command:backup_logs from the terminal, the job runs smoothly and everything works as it should.
While, when the job runs through the cron * * * * * /usr/bin/php /var/app/current/artisan command:backup_logs it returns the following error in the 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)
........
It gives a PRODUCTION error on laravel.log, while this is DEVELOPMENT,
and the value is looking for is already set. As I mentioned earlier the upload works fine when I run it from the terminal as a logged user.
I am having the same problem with all the commands and also when I want to run the jobs through the schedule, the same error happens.
Anyone who can shed some light please? Thank you very much!
Solved: https://stackoverflow.com/questions/52371506/laravel-command-returning-different-output-when-executed-by-cron-on-aws-ec2 A ebextensions config file with this solves it:
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
Please or to participate in this conversation.