AWS SDK 또는 CLI와 GetBucketLocation 함께 사용 - AWS SDK 코드 예제

Doc AWS SDK 예제 GitHub 리포지토리에서 사용할 수 있는 SDK 예제가 더 많습니다. AWS

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

AWS SDK 또는 CLI와 GetBucketLocation 함께 사용

다음 코드 예제는 GetBucketLocation의 사용 방법을 보여 줍니다.

CLI
AWS CLI

다음 명령은 my-bucket이라는 버킷의 위치 제약 조건을 가져옵니다(제약 조건이 있는 경우).

aws s3api get-bucket-location --bucket my-bucket

출력:

{ "LocationConstraint": "us-west-2" }
  • API 세부 정보는 AWS CLI 명령 참조GetBucketLocation을 참조하세요.

PowerShell
PowerShell용 도구

예시 1: 이 명령은 제약 조건이 있는 경우 's3testbucket' 버킷에 대한 위치 제약 조건을 반환합니다.

Get-S3BucketLocation -BucketName 'amzn-s3-demo-bucket'

출력:

Value ----- ap-south-1
  • API 세부 정보는 AWS Tools for PowerShell Cmdlet 참조의 GetBucketLocation을 참조하세요.

Rust
SDK for Rust
참고

GitHub에 더 많은 내용이 있습니다. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

async fn show_buckets( strict: bool, client: &Client, region: BucketLocationConstraint, ) -> Result<(), S3ExampleError> { let mut buckets = client.list_buckets().into_paginator().send(); let mut num_buckets = 0; let mut in_region = 0; while let Some(Ok(output)) = buckets.next().await { for bucket in output.buckets() { num_buckets += 1; if strict { let r = client .get_bucket_location() .bucket(bucket.name().unwrap_or_default()) .send() .await?; if r.location_constraint() == Some(&region) { println!("{}", bucket.name().unwrap_or_default()); in_region += 1; } } else { println!("{}", bucket.name().unwrap_or_default()); } } } println!(); if strict { println!( "Found {} buckets in the {} region out of a total of {} buckets.", in_region, region, num_buckets ); } else { println!("Found {} buckets in all regions.", num_buckets); } Ok(()) }
  • API 세부 정보는 AWS SDK for Rust API 참조GetBucketLocation을 참조하십시오.