

# AWS CLI의 Amazon S3 버킷 수명 주기에 대한 스크립팅 예제
<a name="cli-services-s3-lifecycle-example"></a>

이 주제에서는AWS Command Line Interface(AWS CLI)를 사용하는 Amazon S3 버킷 수명 주기 작업에 대한 bash 스크립팅 예제를 사용합니다. 이 스크립팅 예제에서는 [https://docs.aws.amazon.com/cli/latest/reference/s3api/index.html](https://docs.aws.amazon.com/cli/latest/reference/s3api/index.html) 명령 세트를 사용합니다. 셸 스크립트는 명령줄 인터페이스에서 실행되도록 설계된 프로그램입니다.

**Topics**
+ [시작하기 전에](#cli-services-s3-lifecycle-example-before)
+ [이 예제 정보](#cli-services-s3-lifecycle-example-about)
+ [파일](#cli-services-s3-lifecycle-example-files)
+ [참조](#cli-services-s3-lifecycle-example-references)

## 시작하기 전에
<a name="cli-services-s3-lifecycle-example-before"></a>

아래 예제 중 하나를 실행하려면 먼저 다음 작업을 완료해야 합니다.
+ AWS CLI를 설치하고 구성합니다. 자세한 내용은 [최신 버전의 AWS CLI 설치 또는 업데이트](getting-started-install.md) 및 [AWS CLI에 대한 인증 및 액세스 보안 인증](cli-chap-authentication.md) 섹션을 참조하세요.
+ 사용하는 프로파일에는 예제에서 수행하는 AWS 작업을 허용하는 권한이 있어야 합니다.
+ AWS 모범 사례로서 이 코드에 최소 권한을 부여하거나 태스크를 수행하는 데 필요한 권한만 부여하세요. 자세한 내용은 *IAM 사용 설명서*에서 [최소 권한 부여](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege)를 참조하세요.
+ 이 코드는 일부 AWS 리전에서 테스트되지 않았습니다. 일부 AWS 서비스는 특정 리전에서만 사용할 수 있습니다. 자세한 내용은 *AWS 일반 참조 안내서*에서 [서비스 엔드포인트 및 할당량](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)을 참조하세요.
+ 이 코드를 실행하면 AWS 계정에 요금이 발생할 수 있습니다. 이 스크립트에 의해 생성된 모든 리소스를 사용한 후 제거하는 것은 사용자의 책임입니다.

Amazon S3 서비스에는 다음 용어가 사용됩니다.
+ 버킷 - 최상위 수준의 Amazon S3 폴더입니다.
+ 접두사 - 버킷의 Amazon S3 폴더입니다.
+ 객체 - Amazon S3 버킷에서 호스팅되는 모든 항목입니다.

## 이 예제 정보
<a name="cli-services-s3-lifecycle-example-about"></a>

이 예제는 셸 스크립트 파일의 함수 세트를 사용하여 일부 기본 Amazon S3 작업과 상호 작용하는 방법을 보여줍니다. 함수는 `bucket-operations.sh`라는 셸 스크립트 파일에 있습니다. 다른 파일에서 이러한 함수를 호출할 수 있습니다. 각 스크립트 파일에는 각 함수를 설명하는 주석이 들어 있습니다.

각 단계의 중간 결과를 보려면 `-i` 파라미터와 함께 스크립트를 실행합니다. Amazon S3 콘솔을 사용하여 버킷의 현재 상태 또는 버킷의 내용을 볼 수 있습니다. 스크립트는 프롬프트에서 **Enter** 키를 누르는 경우에만 다음 단계로 진행됩니다.

전체 예제 및 다운로드 가능한 스크립트 파일은 *GitHub*에서 *AWS 코드 예제 리포지토리*의 [Amazon S3 버킷 수명 주기 작업](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/aws-cli/bash-linux/s3/bucket-lifecycle-operations)을 참조하세요.

## 파일
<a name="cli-services-s3-lifecycle-example-files"></a>

에제에는 다음 파일이 들어 있습니다.

**bucket-operations.sh**  
이 기본 스크립트 파일은 다른 파일에서 가져올 수 있습니다. 여기에는 다음 작업을 수행하는 함수가 포함됩니다.  
+ 버킷 생성 및 버킷이 존재하는지 확인
+ 로컬 컴퓨터에서 버킷으로 파일 복사
+ 한 버킷 위치에서 다른 버킷 위치로 파일 복사
+ 버킷의 내용 나열
+ 버킷에서 파일 삭제
+ 버킷 삭제
*GitHub*에서 `[bucket-operations.sh](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/aws-cli/bash-linux/s3/bucket-lifecycle-operations/bucket_operations.sh)`에 대한 코드를 확인하세요.

**test-bucket-operations.sh**  
셸 스크립트 파일 `test-bucket-operations.sh`는 `bucket-operations.sh` 파일을 소싱하고 각 함수를 호출하여 함수를 호출하는 방법을 보여줍니다. 함수를 호출한 후 테스트 스크립트는 생성한 모든 리소스를 제거합니다.  
*GitHub*에서 `[test-bucket-operations.sh](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/aws-cli/bash-linux/s3/bucket-lifecycle-operations/test_bucket_operations.sh)`에 대한 코드를 확인하세요.

**awsdocs-general.sh**  
스크립트 파일 `awsdocs-general.sh`에는 AWS CLI에 대한 고급 코드 예제에서 사용되는 범용 함수가 들어 있습니다.  
*GitHub*에서 `[awsdocs-general.sh](https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/aws-cli/bash-linux/s3/bucket-lifecycle-operations/awsdocs_general.sh)`에 대한 코드를 확인하세요.

## 참조
<a name="cli-services-s3-lifecycle-example-references"></a>

**AWS CLI 참조:** 
+ [https://docs.aws.amazon.com/cli/latest/reference/s3api/index.html](https://docs.aws.amazon.com/cli/latest/reference/s3api/index.html)
+ [https://docs.aws.amazon.com/cli/latest/reference/s3api/create-bucket.html](https://docs.aws.amazon.com/cli/latest/reference/s3api/create-bucket.html)
+ [https://docs.aws.amazon.com/cli/latest/reference/s3api/copy-object.html](https://docs.aws.amazon.com/cli/latest/reference/s3api/copy-object.html)
+ [https://docs.aws.amazon.com/cli/latest/reference/s3api/delete-bucket.html](https://docs.aws.amazon.com/cli/latest/reference/s3api/delete-bucket.html)
+ [https://docs.aws.amazon.com/cli/latest/reference/s3api/delete-object.html](https://docs.aws.amazon.com/cli/latest/reference/s3api/delete-object.html)
+ [https://docs.aws.amazon.com/cli/latest/reference/s3api/head-bucket.html](https://docs.aws.amazon.com/cli/latest/reference/s3api/head-bucket.html)
+ [https://docs.aws.amazon.com/cli/latest/reference/s3api/list-objects.html](https://docs.aws.amazon.com/cli/latest/reference/s3api/list-objects.html)
+ [https://docs.aws.amazon.com/cli/latest/reference/s3api/put-object.html](https://docs.aws.amazon.com/cli/latest/reference/s3api/put-object.html)

**기타 참조:**
+ **Amazon S3 사용 설명서의 [Amazon S3 버킷 작업](https://docs.aws.amazon.com//AmazonS3/latest/userguide/UsingBucket.html)
+ **Amazon S3 사용 설명서의 [Amazon S3 버킷 작업](https://docs.aws.amazon.com//AmazonS3/latest/userguide/UsingObjects.html)
+ AWS SDK 및 AWS CLI 코드 예제를 보고 기여하려면 *GitHub*에서 [AWS 코드 예제 리포지토리](https://github.com/awsdocs/aws-doc-sdk-examples/)를 참조하세요.