LoginSignup
0
2

More than 5 years have passed since last update.

Botoを使用してPythonからAWSを操作する(入門編)

Last updated at Posted at 2018-10-01

はじめに

BotoはPython用のAWSのSDKである。Botoを使用することで、Amazon S3やAmazon EC2をPythonから操作することができる。

インストール

pipを使用してboto3をインストールする。

pip install boto3

準備

~/.aws/credentialsを以下のように作成する。

[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_SECRET_KEY

aws_access_key_idとaws_secret_access_keyはAWSマネジメントコンソールのIAMから作成できる。今回の例では、アクセス権限はAmazonS3FullAccessのみ追加した。

実行

以下を実行すると、Amazon S3のバケット一覧が得られる。バケットを一つも作成していないと何も出力されないので、事前に作成しておく。

import boto3

s3 = boto3.resource('s3')
for bucket in s3.buckets.all():
    print(bucket.name)
0
2
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
2