객체 주석 관리
객체 주석 관리
AWS Management Console, AWS CLI, 또는 AWS SDK를 사용해 Amazon S3 객체에 주석을 추가하고, 검색하고, 삭제할 수 있어요.
출처: 문서
본문
주석 추가 또는 업데이트 (Adding or updating an annotation)
객체에 새 주석을 추가하거나, 페이로드를 교체해 기존 주석을 업데이트할 수 있어요.
S3 콘솔 사용:
- AWS Management Console에 로그인하고 Amazon S3 콘솔(
https://console.aws.amazon.com/s3/)을 엽니다. - Buckets 목록에서 객체가 들어 있는 버킷 이름을 선택해요.
- Objects 목록에서 주석을 달 객체 이름을 선택해요.
- Properties 탭을 선택해요.
- Annotations 섹션으로 스크롤해 Add annotation을 선택해요.
- Name에 주석 이름을 입력해요 (예:
ml.sentiment). 이름은 1~512바이트여야 하고, Unicode 문자, 숫자, 밑줄, 마침표, 하이픈을 포함할 수 있어요. 이름은aws나s3로 시작할 수 없어요. - Choose file을 선택해 주석 콘텐츠를 업로드해요. 파일은 UTF-8로 인코딩 가능하고 최대 1MB 크기여야 해요.
- (선택) Checksums 아래에서 체크섬 알고리즘을 선택해요.
- Add annotation을 선택해요.
참고: 생성된 후 주석의 내용을 보려면 주석을 다운로드해야 해요. S3 콘솔은 주석 내용을 인라인으로 표시하지 않아요.
AWS CLI 사용 — 객체에 주석을 추가·업데이트하려면 put-object-annotation 명령을 사용해요. --annotation-payload 파라미터는 파일 경로를 받아요.
aws s3api put-object-annotation \
--bucket amzn-s3-demo-bucket \
--key myDocument.pdf \
--annotation-name "ml.sentiment" \
--annotation-payload /tmp/sentiment.json
마지막으로 읽은 이후 객체가 덮어쓰여지지 않은 경우에만 주석을 쓰려면 --object-if-match 파라미터에 객체의 현재 ETag를 지정하세요.
aws s3api put-object-annotation \
--bucket amzn-s3-demo-bucket \
--key myDocument.pdf \
--annotation-name "ml.sentiment" \
--annotation-payload /tmp/sentiment.json \
--object-if-match "\"d6eb32081c822ed572b70567826d9d9d\""
AWS SDK 사용 — AWS SDK for Python (Boto3)로 객체에 주석을 추가하는 예시:
import boto3
import json
s3 = boto3.client('s3')
s3.put_object_annotation(
Bucket='amzn-s3-demo-bucket',
Key='myDocument.pdf',
AnnotationName='ml.sentiment',
AnnotationPayload=json.dumps({
'score': 0.95,
'label': 'positive',
'model': 'sentiment-v3'
}).encode('utf-8')
)
주석 검색 (Retrieving annotations)
특정 주석을 검색하거나 객체의 모든 주석을 나열할 수 있어요.
S3 콘솔 사용 — 콘솔에 로그인하고 버킷, 객체를 선택한 뒤 Properties 탭으로 이동해 Annotations 섹션으로 스크롤해요. 주석 내용을 보려면 주석 이름 옆의 Download를 선택해요.
AWS CLI 사용 — 특정 주석을 검색하려면 get-object-annotation 명령을 사용해요.
aws s3api get-object-annotation \
--bucket amzn-s3-demo-bucket \
--key myDocument.pdf \
--annotation-name "ml.sentiment" \
output.json
객체의 모든 주석을 나열하려면 list-object-annotations 명령을 사용해요.
aws s3api list-object-annotations \
--bucket amzn-s3-demo-bucket \
--key myDocument.pdf
AWS SDK 사용 — Boto3로 주석을 검색·나열하는 예시:
import boto3
import json
s3 = boto3.client('s3')
# Retrieve a specific annotation
response = s3.get_object_annotation(
Bucket='amzn-s3-demo-bucket',
Key='myDocument.pdf',
AnnotationName='ml.sentiment'
)
content = json.loads(response['AnnotationPayload'].read())
# List all annotations on an object
response = s3.list_object_annotations(
Bucket='amzn-s3-demo-bucket',
Key='myDocument.pdf'
)
for annotation in response['Annotations']:
print(f"{annotation['AnnotationName']} - {annotation['Size']} bytes")
주석 삭제 (Deleting annotations)
객체에서 특정 주석을 삭제할 수 있어요. 주석 삭제는 영구적이며 되돌릴 수 없어요.
S3 콘솔 사용 — 콘솔에 로그인하고 버킷, 객체를 선택한 뒤 Properties 탭 → Annotations 섹션에서 삭제할 주석을 선택하고 Delete를 선택한 후 삭제를 확인해요.
AWS CLI 사용 — 특정 주석을 삭제하려면 delete-object-annotation 명령을 사용해요.
aws s3api delete-object-annotation \
--bucket amzn-s3-demo-bucket \
--key myDocument.pdf \
--annotation-name "ml.sentiment"
AWS SDK 사용 — Boto3로 주석을 삭제하는 예시:
import boto3
s3 = boto3.client('s3')
s3.delete_object_annotation(
Bucket='amzn-s3-demo-bucket',
Key='myDocument.pdf',
AnnotationName='ml.sentiment'
)