0
1

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 3 years have passed since last update.

LaravelでAWS SDKのS3を扱う

Posted at

LaravelでS3を使うには

  • AWS SDKを使う
  • Flysystemを使う

のどちらかになると思います。
とりあえず今回はSDKを使います。

AWS SDK

composerでの導入

composer require aws/aws-sdk-php

でSDKを導入します。

.envファイルに環境変数の設定

コード上にわざわざ接続情報を書く必要はありません。
環境変数から自動的に持ってきてくれるので、指定された環境変数名に
キー情報を記載しておきます。

.env
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

S3への処理を書く

後はS3Clientを使って好きに操作することが可能です。

use Aws\S3\S3Client;

...

$s3 = new S3Client([
    'version' => 'latest',
    'region' => 'us-east-2'
]);
$result = $s3->listObjects();
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?