* 이 포스팅은 https://developing-soosoo.tistory.com/49 과 연결된 포스팅입니다.
boto3로 S3를 불러올 때 boto3.resourece('s3')를 사용하기도, boto3.client('s3')를 사용하기도 합니다.
이 둘의 차이점이 무엇인지 알아보도록 하겠습니다.
Client
- low-level interface
- botocore library에 있는 JSON service description으로 생성됩니다.
- botocore 패키지는 AWS CLI 뿐만 아니라 boto3와도 공유됩니다.
( botocore 패키지는 AWS CLI와 boto3의 기초가 되는 라이브러리 입니다)
Boto3 Client 장점
- 실제 AWS API와 1대1로 맵핑된다
- 모든 AWS는 client에 의해 작동된다
예제 코드
import boto3
s3=boto3.client('s3')
response=s3.list_buckets()
for bucket in response['Buckets']:
print(f'{bucket["Name"]}')
client를 사용하면, service definition을 사용해 client를 만들기 위해 botocore를 사용합니다
Resource
- client에 비해 higher-level abstraction
- botocore library에 있는 JSON resource description으로 생성됩니다.
- 다양한 AWS와 상호작용하는 객체지향적 인터페이스를 제공합니다.
resource instance 종류
- Identifiers
- Attributes
- Actions
예제 코드
- Identifiers
import boto3
s3=boto3.resource('s3')
bucket=s3.Bucket(name="my_bucket") # Bucket 으로 접근
obj=s3.Object(bucket_name="my_bucket", key="test.py")
- Actions
import boto3
s3=boto3.resoure('s3')
obj=s3.Object(bucket_name="my_bucket", key="test.py") # Object로 바로 접근
response=obj.get()
'AWS' 카테고리의 다른 글
3-0. AWS Amazon Rekognition Video 구성 (SNS, SQS) (0) | 2021.12.29 |
---|---|
2. AWS Amazon Rekognition 입문 가이드 (이미지 작업하기) (0) | 2021.12.29 |
1-1. AWS S3 사용하기 (boto3 이용) (0) | 2021.12.23 |
1-0. AWS S3 시작하기 (bucket 만들기) (0) | 2021.12.23 |
0. AWS 시작하기 (AWS CLI , AWS SDK setting) (0) | 2021.12.23 |