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

AWS SDK 예제 GitHub 리포지토리에 더 많은 AWS문서 SDK 예제가 있습니다.

AWS SDK 또는 CLI와 함께 GetBucketLocation 사용

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

CLI
AWS CLI

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

aws s3api get-bucket-location --bucket amzn-s3-demo-bucket

출력:

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

PowerShell
Tools for PowerShell V4

예제 1: 이 명령에서는 제약 조건이 있는 경우 'amzn-s3-demo-bucket' 버킷에 대한 위치 제약 조건을 반환합니다.

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

출력:

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

Tools for PowerShell V5

예제 1: 이 명령에서는 제약 조건이 있는 경우 'amzn-s3-demo-bucket' 버킷에 대한 위치 제약 조건을 반환합니다.

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

출력:

Value ----- ap-south-1
  • API 세부 정보는 AWS Tools for PowerShell Cmdlet 참조(V5)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을 참조하십시오.