getBucketLocation method

Future<GetBucketLocationOutput> getBucketLocation({
  1. required String bucket,
  2. String? expectedBucketOwner,
})
Returns the Region the bucket resides in. You set the bucket's Region using the LocationConstraint request parameter in a CreateBucket request. For more information, see CreateBucket. When you use this API operation with an access point, provide the alias of the access point in place of the bucket name.

When you use this API operation with an Object Lambda access point, provide the alias of the Object Lambda access point in place of the bucket name. If the Object Lambda access point alias in a request is not valid, the error code InvalidAccessPointAliasError is returned. For more information about InvalidAccessPointAliasError, see List of Error Codes. The following operations are related to GetBucketLocation:

Parameter bucket : The name of the bucket for which to get the location.

When you use this API operation with an access point, provide the alias of the access point in place of the bucket name.

When you use this API operation with an Object Lambda access point, provide the alias of the Object Lambda access point in place of the bucket name. If the Object Lambda access point alias in a request is not valid, the error code InvalidAccessPointAliasError is returned. For more information about InvalidAccessPointAliasError, see List of Error Codes.

Parameter expectedBucketOwner : The account ID of the expected bucket owner. If the account ID that you provide does not match the actual owner of the bucket, the request fails with the HTTP status code 403 Forbidden (access denied).

Implementation

Future<GetBucketLocationOutput> getBucketLocation({
  required String bucket,
  String? expectedBucketOwner,
}) async {
  final headers = <String, String>{
    if (expectedBucketOwner != null)
      'x-amz-expected-bucket-owner': expectedBucketOwner.toString(),
  };
  final $result = await _protocol.send(
    method: 'GET',
    requestUri: '/${Uri.encodeComponent(bucket)}?location',
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  return GetBucketLocationOutput.fromXml($result.body);
}