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

AWS-MFA認証のアカウントでAws\S3\S3Clientを利用するには

Last updated at Posted at 2021-10-22

MFA認証が必要なAWSアカウントに対してWEB用SDKのS3Clientでアクセスする方法です。
AWSリソース間でのアクセスはRoleでの権限設定が推奨されていますが、例えばローカル開発環境からテストでS3にアクセスするとき、AWS_SESSION_TOKENの設定が必要になります。

対策はaws_session_tokenを配列に指定してオブジェクトを生成するだけです。

    $s3 = new S3Client([
        'aws_access_key' =>  env('AWS_ACCESS_KEY'),
        'aws_secret_key' => env('AWS_SECRET_ACCESS_KEY'),
        'aws_session_token' => env('AWS_SESSION_TOKEN'),
        'region' =>  env('AWS_DEFAULT_REGION'),
        'version' => '2006-03-01'
    ]);

session tokenの取得はcliから。
https://aws.amazon.com/jp/premiumsupport/knowledge-center/authenticate-mfa-cli/

0
0
1

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
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?