0

I am trying to get my assets stored in S3 by calling a API implemented as Lambda function using Bref Serverless Package. I am using Laravel. A call to Storage::directories(); give the following error.

message: Error executing "ListObjects" on "https://calmed-storage.s3.us-west-2.amazonaws.com/?prefix=&delimiter=%2F&encoding-type=url"; AWS HTTP error: Client error: GET https://mys3-storage.s3.us-west-2.amazonaws.com/?prefix=&delimiter=%2F&encoding-type=url resulted in a 403 Forbidden response: The AWS Access Key Id you provided (truncated...) InvalidAccessKeyId (client): The AWS Access Key Id you provided does not exist in our records. - InvalidAccessKeyIdThe AWS Access Key Id you provided does not exist in our records.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Shiju S S
  • 51
  • 1
  • 9

3 Answers3

0

Well the error says it all, you need to send a correct AWS key when communicating with their API.

if you use league/flysystem-aws-s3-v3 as described in the official Laravel docs then you need to set the AWS S3 environment variables listed below in your .env file

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=
AWS_BUCKET=
AWS_URL=

To get an access key you need to create a user with correct access permissions is Amazon. This tutorial will help you with that.

henrik
  • 1,558
  • 3
  • 14
  • 29
  • .env file is set as per documentation. S3 permissions and roles set as per documentation in aws. Nothing is happening. – Shiju S S Nov 10 '20 at 16:21
  • There is an issue with the access key that you are using. Double check your IAM user. https://aws.amazon.com/premiumsupport/knowledge-center/access-key-does-not-exist/ – henrik Nov 11 '20 at 10:31
  • Answers here on stack overflow can only point you in the right direction, we are not a amazon support platform. If you have a specific question regarding the integration please rephrase your question. Otherwise accept my answer and continue by contacting Amazon support. – henrik Nov 11 '20 at 11:54
  • I think it has noting to with AWS IAM roles. Since all settings were correctly done. It was working perfectly in local and ec2 instance, The issue was only when executed as Lambda function. Aws-sdk-php was sending another Access ID and Secret key instead of the one stored in my .env file. – Shiju S S Nov 12 '20 at 14:08
0

I was using Laravel and credentials were stored in .env file. aws-sdk-php was somehow changing the Access ID and Secret Key. I don't know why. The issue was solved when I hard coded Access ID and Secret Key in filesystems.php.

Shiju S S
  • 51
  • 1
  • 9
0

It seems you are using Laravel.

If so, you need to fix config/filesystems.php as described here: https://bref.sh/docs/frameworks/laravel.html#file-storage-on-s3

Because of a misconfiguration shipped in Laravel, the S3 authentication will not work out of the box. You will need to add this line in config/filesystems.php:

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
+           'token' => env('AWS_SESSION_TOKEN'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],
Matthieu Napoli
  • 48,448
  • 45
  • 173
  • 261