Here are the steps to access AWS S3 using Python in Visual Studio 2017.
Windows 7 Professional SP1 64bit Visual Studio 2017 Community 15.2 (26430.6) Python 3.6.0 boto3 1.4.4
Please refer to here for environment construction and Python project creation. http://qiita.com/akabei/items/a3b8b62f1cf34b683121
Create a "Python application" in your new project.
From your project's Python environment, right-click Python 3.6 (64bit) (global default) and select Install Python Package ...
Enter "boto3" in the text box and select "Install boto3 (1.4.4)".
When the dialog that requires administrator privileges is displayed, select "Promote Now".
After installing the package, "boto3 (1.4.4)" will be displayed in "Python 3.6 (64bit) (global default)".
Write a program to display the S3 bucket list in s3bucket.py.
s3bucket.py
import boto3
session = boto3.Session(aws_access_key_id='XXXXXXXXXXXXXXXXXX',
aws_secret_access_key='YYYYYYYYYYYYYYYYYYYYYYYYYYYY',
region_name='ap-northeast-1')
s3 = session.resource('s3')
for bucket in s3.buckets.all():
print(bucket.name)
If you have set the authentication information with the aws configure command in advance, boto3.Session () is unnecessary as shown below.
s3bucket.py
import boto3
s3 = boto3.resource('s3')
for bucket in s3.buckets.all():
print(bucket.name)
If you can execute it and get the bucket list, you are done.
Recommended Posts