AWS는 여러 언어로 AWS를 관리할 수 있도록 해주는 SDK (Software Development Kit)를 제공합니다. 개발자는 AWS SDK를 통해 AWS 리소스를 코드로 관리할 수 있어, 자동화된 스크립트를 작성하거나 애플리케이션을 개발하는 데 활용할 수 있습니다.
AWS Boto3는 Python용 AWS SDK로, AWS 서비스를 생성하고, 설정하고, 관리하는 데 사용할 수 있습니다.
Installation
Install Python
Boto3를 설치하려면 Python의 버전이 3.8 이상이어야 합니다. Python 3.7 버전 이하에서도 Boto3를 사용할 수 있지만, 최신 기능을 모두 사용하려면 Python 3.8 이상을 권장하고 있습니다.
Install Boto3
Boto3는 파이썬의 'pip' 모듈을 통해 설치할 수 있습니다.
$ pip install boto3
Configuration
Boto3를 사용하기 위해서는 Boto3가 사용할 IAM 유저가 있어야 합니다. 이미 유저가 있다면 그 유저에 접속할 수 있는 Access Key도 필요합니다. AWS CLI가 설치되어 있다면, 'aws configure' 명령어를 통해 자격 증명을 설정할 수 있습니다.
$ aws configure
AWS Access Key ID [None]: YOUR_ACCESS_KEY
AWS Secret Access Key [None]: YOUR_SECRET_KEY
Default region name [None]:
Default output format [None]:
또는 아래의 파일들을 만들거나 수정해서 설정해도 됩니다.
$ tree .aws
.aws
├── config # Default region, Default output
└── credentials # AWS Access Key ID, AWS Secret Access Key
Using Boto3
아래의 코드는 Boto3를 사용하여 모든 S3 버킷의 이름을 출력하는 예시입니다.
boto3.resource를 사용하여 S3 리소스를 지정하고, buckets.all() 메서드를 사용하여 모든 S3 버킷의 이름을 출력했습니다.
import boto3
def hello_s3():
s3_resource = boto3.resource("s3")
print("Hello, Amazon S3! Let's list your buckets:")
for bucket in s3_resource.buckets.all():
print(f"\t{bucket.name}")
if __name__ == "__main__":
hello_s3()
참고
https://boto3.amazonaws.com/v1/documentation/api/latest/index.html
Boto3 1.35.52 documentation
Next Quickstart
boto3.amazonaws.com
https://docs.aws.amazon.com/code-library/latest/ug/python_3_s3_code_examples.html
Amazon S3 examples using SDK for Python (Boto3) - AWS SDK Code Examples
Thanks for letting us know this page needs work. We're sorry we let you down. If you've got a moment, please tell us how we can make the documentation better.
docs.aws.amazon.com