Closed
Description
Describe the bug
S3.headBucket doesn't throw NotFound error when bucket doesn't exist
SDK version number
$ yarn list aws-sdk
└─ aws-sdk@2.693.0
$ yarn list @aws-sdk/client-s3
└─ @aws-sdk/client-s3@1.0.0-gamma.2
Is the issue in the browser/Node.js/ReactNative?
Node.js
Details of the browser/Node.js/ReactNative version
$ node -v
v12.17.0
To Reproduce (observed behavior)
Code
const AWS = require("aws-sdk");
const { S3 } = require("@aws-sdk/client-s3");
(async () => {
let response;
const region = "us-west-2";
const Bucket = `test-bucket-${Math.ceil(Math.random() * 10 ** 10)}`;
const v2Client = new AWS.S3({ region });
const v3Client = new S3({ region });
await v2Client.createBucket({ Bucket }).promise();
await v2Client.waitFor("bucketExists", { Bucket }).promise();
response = await v2Client.headBucket({ Bucket }).promise();
console.log(`v2 headBucket: ${JSON.stringify(response, null, 2)}`);
response = await v3Client.headBucket({ Bucket });
console.log(`v3 headBucket: ${JSON.stringify(response, null, 2)}`);
await v2Client.deleteBucket({ Bucket }).promise();
await v2Client.waitFor("bucketNotExists", { Bucket }).promise();
try {
response = await v2Client.headBucket({ Bucket }).promise();
console.log(`v2 headBucket: ${JSON.stringify(response, null, 2)}`);
} catch (e) {
console.log(`v2 Error:`);
console.log(e);
}
try {
response = await v3Client.headBucket({ Bucket });
console.log(`v3 headBucket: ${JSON.stringify(response, null, 2)}`);
} catch (e) {
console.log(`v3 Error:`);
console.log(e);
}
})();
Details
v2 headBucket: {}
v3 headBucket: {
"$metadata": {
"httpStatusCode": 200,
"httpHeaders": {
"x-amz-id-2": "WESS+DcnNwmJOUmAUBquXI9U2TcNVliQKk1WPVoAHxFIwvXDVNSdI5Ya2B1MkqdIqwSBH3Wc+Ag=",
"x-amz-request-id": "94F2FBB046EA4A8F",
"date": "Wed, 08 Jul 2020 01:31:10 GMT",
"x-amz-bucket-region": "us-west-2",
"content-type": "application/xml",
"transfer-encoding": "chunked",
"server": "AmazonS3"
},
"retries": 0,
"totalRetryDelay": 0
}
}
v2 Error:
NotFound: null
at Request.extractError (/Users/trivikr/workspace/aws-sdk-js-tests/node_modules/aws-sdk/lib/services/s3.js:811:35)
at Request.callListeners (/Users/trivikr/workspace/aws-sdk-js-tests/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/Users/trivikr/workspace/aws-sdk-js-tests/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/Users/trivikr/workspace/aws-sdk-js-tests/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/Users/trivikr/workspace/aws-sdk-js-tests/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/Users/trivikr/workspace/aws-sdk-js-tests/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /Users/trivikr/workspace/aws-sdk-js-tests/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/Users/trivikr/workspace/aws-sdk-js-tests/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/Users/trivikr/workspace/aws-sdk-js-tests/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/Users/trivikr/workspace/aws-sdk-js-tests/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
code: 'NotFound',
region: null,
time: 2020-07-08T01:31:09.928Z,
requestId: 'D28E236715974621',
extendedRequestId: 'TKSth2YgdqhB7+Lk9yhI8P1flSVHhWxyiOifXmiLxAUFu8hnl7ZJc27+n3e++i/KenqTOla6570=',
cfId: undefined,
statusCode: 404,
retryable: false,
retryDelay: 25.782346166635396
}
v3 headBucket: {
"$metadata": {
"httpStatusCode": 200,
"httpHeaders": {
"x-amz-id-2": "WrOLC0sgp6EglKp1oTg5zBj2VUzT6u3AbgV1pt0n1dB/e4VDLCnNn+d+Ak0qoZPgQ1EuhZXKIl4=",
"x-amz-request-id": "B38EE1F02316A32D",
"date": "Wed, 08 Jul 2020 01:31:10 GMT",
"x-amz-bucket-region": "us-west-2",
"content-type": "application/xml",
"transfer-encoding": "chunked",
"server": "AmazonS3"
},
"retries": 0,
"totalRetryDelay": 0
}
}
Expected behavior
S3.headBucket should throw error when bucket doesn't exist