I have my Laravel app which let users upload and download files from an S3 bucket.
Running the app locally (with php artisan serve) everything works fine but when I deploy the app with “serverless deploy” and test the app from the “execute-api.us-east-1.amazonaws.com” it doesn’t work…
I’ve tried to just list the files under the bucket and I get an “Access Denied” error.
My first thought was that somehow the .env file was messed up but downloading the “laravel.zip” from the serverless deploy bucket I see that the env file is fine…
I figured it out.
So apparently serverless puts it’s own AWS_SECRET_ACCESS_KEY on runtime level (so in the .env was correct). If you want to use S3 you have to add a new line to your env with a different name and use that under filesystem.php.
For good measure on .env I copied all the AWS parameters like this:
CUSTOM_AWS_ACCESS_KEY_ID= CUSTOM_AWS_SECRET_ACCESS_KEY= CUSTOM_AWS_DEFAULT_REGION= CUSTOM_AWS_BUCKET=CUSTOM_AWS_USE_PATH_STYLE_ENDPOINT=
And created a new storage under filesystem like this
'custom_s3' => [ 'driver' => 's3', 'key' => env('CUSTOM_AWS_ACCESS_KEY_ID'), 'secret' => env('CUSTOM_AWS_SECRET_ACCESS_KEY'), 'region' => env('CUSTOM_AWS_DEFAULT_REGION'), 'bucket' => env('CUSTOM_AWS_BUCKET'), 'url' => env('AWS_URL'), 'endpoint' => env('AWS_ENDPOINT'), 'use_path_style_endpoint' => env('CUSTOM_AWS_USE_PATH_STYLE_ENDPOINT', false), 'throw' => false, ],