getBucketPolicy method

Future<GetBucketPolicyOutput> getBucketPolicy({
  1. required String bucket,
  2. String? expectedBucketOwner,
})

Returns the policy of a specified bucket. If you are using an identity other than the root user of the AWS account that owns the bucket, the calling identity must have the GetBucketPolicy permissions on the specified bucket and belong to the bucket owner's account in order to use this operation.

If you don't have GetBucketPolicy permissions, Amazon S3 returns a 403 Access Denied error. If you have the correct permissions, but you're not using an identity that belongs to the bucket owner's account, Amazon S3 returns a 405 Method Not Allowed error. For more information about bucket policies, see Using Bucket Policies and User Policies.

The following operation is related to GetBucketPolicy:

Parameter bucket : The bucket name for which to get the bucket policy.

Parameter expectedBucketOwner : The account id of the expected bucket owner. If the bucket is owned by a different account, the request will fail with an HTTP 403 (Access Denied) error.

Implementation

Future<GetBucketPolicyOutput> getBucketPolicy({
  required String bucket,
  String? expectedBucketOwner,
}) async {
  ArgumentError.checkNotNull(bucket, 'bucket');
  final headers = <String, String>{
    if (expectedBucketOwner != null)
      'x-amz-expected-bucket-owner': expectedBucketOwner.toString(),
  };
  final $result = await _protocol.sendRaw(
    method: 'GET',
    requestUri: '/${Uri.encodeComponent(bucket)}?policy',
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  return GetBucketPolicyOutput(
    policy: await $result.stream.bytesToString(),
  );
}