Jump to Content

Class HeadBucketCommandProtected

This action is useful to determine if a bucket exists and you have permission to access it. The action returns a 200 OK if the bucket exists and you have permission to access it.

If the bucket does not exist or you do not have permission to access it, the HEAD request returns a generic 404 Not Found or 403 Forbidden code. A message body is not included, so you cannot determine the exception beyond these error codes.

To use this operation, you must have permissions to perform the s3:ListBucket action. The bucket owner has this permission by default and can grant this permission to others. For more information about permissions, see Permissions Related to Bucket Subresource Operations and Managing Access Permissions to Your Amazon S3 Resources.

To use this API against an access point, you must provide the alias of the access point in place of the bucket name or specify the access point ARN. When using the access point ARN, you must direct requests to the access point hostname. The access point hostname takes the form AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using the Amazon Web Services SDKs, you provide the ARN in place of the bucket name. For more information see, Using access points.


Use a bare-bones client and the command you need to make an API call.

import { S3Client, HeadBucketCommand } from "@aws-sdk/client-s3"; // ES Modules import
// const { S3Client, HeadBucketCommand } = require("@aws-sdk/client-s3"); // CommonJS import
const client = new S3Client(config);
const command = new HeadBucketCommand(input);
const response = await client.send(command);



NotFound (client fault)

The specified content does not exist.


To determine if bucket exists

// This operation checks to see if a bucket exists.
const input = {
"Bucket": "acl1"
const command = new HeadBucketCommand(input);
await client.send(command);
// example id: to-determine-if-bucket-exists-1473110292262




middlewareStack: MiddlewareStack<HeadBucketCommandInput, HeadBucketCommandOutput>