1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LaravelでS3アクセスが403 Forbiddenエラー

Last updated at Posted at 2020-09-07

Laraelで以下のようなコードを書いた時に

Storage::disk('s3')->put('hoge.csv', 'あいう');
Error executing "PutObject" on "https://bucket-name.s3.ap-northeast-1.amazonaws.com/hoge.csv"; AWS HTTP error: Client error: `PUT https://bucket-name.s3.ap-northeast-1.amazonaws.com/hoge.csv` resulted in a `403 Forbidden` response: ...

といったエラーが表示された。
S3の権限設定はconfig/filesystems.phpで行うため該当ファイルを見ると、シークレットアクセスキーが間違っていることを確認。修正して再実行。しかしまったく同じエラーが出続けます。
バケットポリシーやIAMの設定を見直しても問題なく、aws cliからPutObjectを試してみるとうまくいくため権限は設定できているようだった。

キャッシュが原因

原因はLaravelのキャッシュ設定で

php artisan cache:clear
php artisan config:clear
php artisan config:cache

上記コマンド実行でLaraelのキャッシュをクリアしたところ問題なくPutObjectができるようになった(おそらくどれか一つのコマンドでいいと思うが未検証)。最初に間違ってシークレットアクセスキーを設定してしまったものをキャッシュしてしまい、永遠にエラーが吐かれていたようだった。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?