Doc AWSSDK 예제 GitHub 리포지토리에서 더 많은 SDK 예제를 사용할 수 있습니다. AWS
기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
AWSSDK와 PutObjectAnnotation 함께 사용
다음 코드 예시는 PutObjectAnnotation의 사용 방법을 보여줍니다.
작업 예제는 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 다음 코드 예제에서는 컨텍스트 내에서 이 작업을 확인할 수 있습니다.
- Python
-
- SDK for Python (Boto3)
-
def put_object_annotation(
self,
bucket_name: str,
object_key: str,
annotation_name: str,
annotation_payload: str,
) -> dict:
"""
Attaches a named annotation payload to an S3 object.
:param bucket_name: The name of the bucket containing the object.
:param object_key: The key of the object to annotate.
:param annotation_name: The name of the annotation (1-512 bytes).
:param annotation_payload: The annotation content (1 byte to 1 MiB).
:return: A dict containing the PutObjectAnnotation response with ETag.
:raises ClientError: If the annotation name is invalid
(InvalidAnnotationName) or another error occurs.
"""
try:
response = self.s3_client.put_object_annotation(
Bucket=bucket_name,
Key=object_key,
AnnotationName=annotation_name,
AnnotationPayload=annotation_payload.encode("utf-8"),
)
logger.info(
"Put annotation '%s' on object '%s' in bucket '%s'. ETag: %s",
annotation_name,
object_key,
bucket_name,
response.get("ETag", "N/A"),
)
return response
except ClientError as err:
if err.response["Error"]["Code"] == "InvalidAnnotationName":
logger.error(
"Annotation name '%s' is invalid. Names must be 1-512 bytes, "
"UTF-8 encoded, and cannot start with 'aws' or 's3'.",
annotation_name,
)
raise