이 페이지는 볼트와 2012년의 원래 REST API를 사용하는 Amazon Glacier 서비스의 기존 고객에게만 해당됩니다.
아카이브 스토리지 솔루션을 찾고 있다면 Amazon Glacier Amazon S3, S3 Glacier Flexible Retrieval 및 S3S3 Glacier Deep Archive의 Amazon Glacier 스토리지 클래스를 사용하는 것이 좋습니다. 이러한 스토리지 옵션에 대한 자세한 내용은 Amazon Glacier 스토리지 클래스를 참조하세요.
Amazon Glacier(기존 독립 실행형 볼트 기반 서비스)는 2025년 12월 15일부터 기존 고객에게 영향을 주지 않고 더 이상 신규 고객을 받지 않습니다. Amazon Glacier는 데이터를 볼트에 저장하고 Amazon S3 및 Amazon S3 Glacier 스토리지 클래스와 구별되는 자체 APIs가 있는 독립 실행형 서비스입니다. 기존 데이터는 Amazon Glacier에서 무기한으로 안전하고 액세스할 수 있습니다. 마이그레이션이 필요하지 않습니다. 저비용 장기 아카이브 스토리지의 경우는 S3 버킷 기반 API, 전체 가용성, 저렴한 비용 및 서비스 통합을 통해 우수한 고객 경험을 제공하는 Amazon S3 Glacier 스토리지 클래스를 AWS 권장합니다. S3 APIs AWS 리전 AWS 향상된 기능을 원하는 경우 Amazon Glacier 볼트에서 Amazon S3 Glacier 스토리지 클래스로 데이터를 전송하기 위한 솔루션 지침을 사용하여 Amazon S3 Glacier 스토리지 클래스로 마이그레이션하는 것이 좋습니다. AWS Amazon Glacier Amazon S3
기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
AWS SDK를 사용하여 Amazon Glacier 아카이브 콘텐츠 가져오기 및 아카이브 삭제
다음 코드 예제는 다음과 같은 작업을 수행하는 방법을 보여줍니다.
- Python
-
- SDK for Python (Boto3)
-
Amazon Glacier 작업을 래핑하는 클래스를 생성합니다.
import argparse
import logging
import os
import boto3
from botocore.exceptions import ClientError
logger = logging.getLogger(__name__)
class GlacierWrapper:
"""Encapsulates Amazon S3 Glacier API operations."""
def __init__(self, glacier_resource):
"""
:param glacier_resource: A Boto3 Amazon S3 Glacier resource.
"""
self.glacier_resource = glacier_resource
@staticmethod
def list_jobs(vault, job_type):
"""
Lists jobs by type for the specified vault.
:param vault: The vault to query.
:param job_type: The type of job to list.
:return: The list of jobs of the requested type.
"""
job_list = []
try:
if job_type == "all":
jobs = vault.jobs.all()
elif job_type == "in_progress":
jobs = vault.jobs_in_progress.all()
elif job_type == "completed":
jobs = vault.completed_jobs.all()
elif job_type == "succeeded":
jobs = vault.succeeded_jobs.all()
elif job_type == "failed":
jobs = vault.failed_jobs.all()
else:
jobs = []
logger.warning("%s isn't a type of job I can get.", job_type)
for job in jobs:
job_list.append(job)
logger.info("Got %s %s job %s.", job_type, job.action, job.id)
except ClientError:
logger.exception("Couldn't get %s jobs from %s.", job_type, vault.name)
raise
else:
return job_list
@staticmethod
def get_job_output(job):
"""
Gets the output of a job, such as a vault inventory or the contents of an
archive.
:param job: The job to get output from.
:return: The job output, in bytes.
"""
try:
response = job.get_output()
out_bytes = response["body"].read()
logger.info("Read %s bytes from job %s.", len(out_bytes), job.id)
if "archiveDescription" in response:
logger.info(
"These bytes are described as '%s'", response["archiveDescription"]
)
except ClientError:
logger.exception("Couldn't get output for job %s.", job.id)
raise
else:
return out_bytes
@staticmethod
def delete_archive(archive):
"""
Deletes an archive from a vault.
:param archive: The archive to delete.
"""
try:
archive.delete()
logger.info(
"Deleted archive %s from vault %s.", archive.id, archive.vault_name
)
except ClientError:
logger.exception("Couldn't delete archive %s.", archive.id)
raise
@staticmethod
def delete_vault(vault):
"""
Deletes a vault.
:param vault: The vault to delete.
"""
try:
vault.delete()
logger.info("Deleted vault %s.", vault.name)
except ClientError:
logger.exception("Couldn't delete vault %s.", vault.name)
raise
래퍼 클래스의 함수를 직접 호출하여 완료된 작업에서 아카이브 콘텐츠를 가져온 다음 아카이브를 삭제합니다.
def retrieve_demo(glacier, vault_name):
"""
Shows how to:
* List jobs for a vault and get job status.
* Get the output of a completed archive retrieval job.
* Delete an archive.
* Delete a vault.
:param glacier: A Boto3 Amazon S3 Glacier resource.
:param vault_name: The name of the vault to query for jobs.
"""
vault = glacier.glacier_resource.Vault("-", vault_name)
try:
vault.load()
except ClientError as err:
if err.response["Error"]["Code"] == "ResourceNotFoundException":
print(
f"\nVault {vault_name} doesn't exist. You must first run this script "
f"with the --upload flag to create the vault."
)
return
else:
raise
print(f"\nGetting completed jobs for {vault.name}.")
jobs = glacier.list_jobs(vault, "completed")
if not jobs:
print("\nNo completed jobs found. Give it some time and try again later.")
return
retrieval_job = None
for job in jobs:
if job.action == "ArchiveRetrieval" and job.status_code == "Succeeded":
retrieval_job = job
break
if retrieval_job is None:
print(
"\nNo ArchiveRetrieval jobs found. Give it some time and try again "
"later."
)
return
print(f"\nGetting output from job {retrieval_job.id}.")
archive_bytes = glacier.get_job_output(retrieval_job)
archive_str = archive_bytes.decode("utf-8")
print("\nGot archive data. Printing the first 10 lines.")
print(os.linesep.join(archive_str.split(os.linesep)[:10]))
print(f"\nDeleting the archive from {vault.name}.")
archive = glacier.glacier_resource.Archive(
"-", vault.name, retrieval_job.archive_id
)
glacier.delete_archive(archive)
print(f"\nDeleting {vault.name}.")
glacier.delete_vault(vault)
AWS SDK 개발자 안내서 및 코드 예제의 전체 목록은 섹션을 참조하세요AWS SDK에서 Amazon Glacier 사용. 이 주제에는 시작하기에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.