Help us understand the problem. What is going on with this article?

boto3 で デフォルトprofile以外を使う

More than 3 years have passed since last update.

デフォルトの場合

import boto3

s3 = boto3.resource('s3')
for bucket in s3.buckets.all():
    print(bucket.name)

ACCESS_KEY, SECRET_KEYを指定

ドキュメント

import boto3
from boto3.session import Session

session = Session(aws_access_key_id='<YOUR ACCESS KEY ID>',
                  aws_secret_access_key='<YOUR SECRET KEY>',
                  region_name='<REGION NAME>')

s3 = session.resource('s3')

~/.aws/credentials の profile名で指定する

Session に profile_name を渡す。

ドキュメント 見ても分からず、githubのissue で発見

import boto3
from boto3.session import Session

profile = '<YOUR_PROFILE_NAME>'
session = Session(profile_name=profile)

s3 = session.resource('s3')
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away