Determining whether you can access a directory bucket - Amazon Simple Storage Service

Determining whether you can access a directory bucket

The following AWS SDK examples show how to use the HeadBucket API operation to determine if an Amazon S3 directory bucket exists and if you have permission to access it.

The following AWS SDK for Java 2.x example shows how to determine if a bucket exists and if you have permission to access it.

SDK for Java 2.x

AWS SDK for Java 2.x

public static void headBucket(S3Client s3Client, String bucketName) { try { HeadBucketRequest headBucketRequest = HeadBucketRequest .builder() .bucket(bucketName) .build(); s3Client.headBucket(headBucketRequest); System.out.format("Amazon S3 bucket: \"%s\" found.", bucketName); } catch (S3Exception e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }

The following head-bucket example command shows how you can use the AWS CLI to determine if a directory bucket exists and if you have permission to access it. To run this command, replace the user input placeholders with your own information.

aws s3api head-bucket --bucket bucket-base-name--zone-id--x-s3

For more information, see head-bucket in the AWS CLI Command Reference.

Warning Javascript is disabled or is unavailable in your browser.

To use the Amazon Web Services Documentation, Javascript must be enabled. Please refer to your browser's Help pages for instructions.

Did this page help you? - Yes

Thanks for letting us know we're doing a good job!

If you've got a moment, please tell us what we did right so we can do more of it.

Did this page help you? - No

Thanks for letting us know this page needs work. We're sorry we let you down.

If you've got a moment, please tell us how we can make the documentation better.

AltStyle によって変換されたページ (->オリジナル) /