You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Vector bucket
DeleteVectorBucketPolicy(TOS Vectors Node.js SDK)
Copy page
Download PDF
DeleteVectorBucketPolicy(TOS Vectors Node.js SDK)
The deleteVectorBucketPolicy API deletes the IAM policy of a vector bucket. This article explains how to use the deleteVectorBucketPolicy API via the TOS Vectors Node.js SDK to perform this operation.​
Notes​
  • To prevent key leakage, the sample code reads the Access Key ID and Secret Access Key from environment variables. Before using the SDK, configure long-term access credentials. For details, see configuring long-term access credentials.​
  • The TOS Vectors Node.js SDK supports temporary access credentials and also allows configuring timeout and retry policies. You can flexibly set these according to your business needs to enhance application security. For details, see common configuration scenarios.​
Permissions required​
The main account has all permissions by default, but IAM users have no permissions by default. If you want a sub-account to execute the deleteVectorBucketPolicy operation, the main account must grant the following permissions to the sub-account through IAM policies and bucket policies:​
tosvectors:DeleteVectorBucketPolicy​
Code example​
Delete vector bucket policy - basic deletion case​
​
// Delete vector bucket policy - basic deletion case​
​
import {​
TosVectorsClient,​
TosClientError,​
TosServerError,​
} from "@volcengine/tos-sdk";​
​
// Get authentication info and configuration from environment variables​
const client = new TosVectorsClient({​
accessKeyId: process.env["TOS_ACCESS_KEY"], // TOS_ACCESS_KEY: your Access Key ID​
accessKeySecret: process.env["TOS_SECRET_KEY"], // TOS_SECRET_KEY: your Secret Key​
region: 'Provide your region',​
endpoint: 'Provide your vector endpoint',​
});​
​
const vectorBucketName = 'Provide your vector bucket name';​
const accountId = process.env["TOS_ACCOUNT_ID"];​
​
/**​
* handle possible errors during sdk calls.​
*@paramerror the error object caught​
*/​
function handleError(error: Error) {​
if (error instanceof TosClientError) {​
// client exceptions, usually caused by parameter errors or network issues​
console.log("Client Error:");​
console.log(" Message:", error.message);​
if (error.stack) {​
console.log(" Stack:", error.stack);​
}​
} else if (error instanceof TosServerError) {​
// server exceptions, indicating the request was received but failed to process​
console.log("Server Error:");​
console.log(" Request ID:", error.requestId);​
console.log(" Status Code:", error.statusCode);​
console.log(" Code:", error.code);​
console.log(" Message:", error.message);​
console.log(" Headers:", error.headers);​
} else {​
// other unknown exceptions​
console.log("Unexpected Error:");​
console.log(" Message:", error.message);​
}​
}​
​
async function main() {​
try {​
console.log(`Start deleting the policy for vector bucket ${vectorBucketName} (basic deletion use case)...`);​
​
// 1. Prepare parameters required by the api according to the use case scenario.​
const params = {​
vectorBucketName,​
accountID: accountId,​
};​
​
// 2. Call deleteVectorBucketPolicy to remove the policy of the specified vector bucket.​
const result = await client.deleteVectorBucketPolicy(params);​
​
// 3. Print common return fields and business data.​
console.log("Delete vector bucket policy request has been completed:");​
console.log(" Request ID:", result.requestId);​
console.log(" Status Code:", result.statusCode);​
console.log(" Headers:", result.headers);​
// DeleteVectorBucketPolicyOutput is {}, data is usually an empty object but still needs to be printed.​
console.log(" Data (DeleteVectorBucketPolicyOutput):", result.data);​
} catch (error: any) {​
// All API calls must be inside try-catch blocks and errors should be handled uniformly via handleError​
handleError(error);​
}​
​
// Use a separate try-catch to call getVectorBucketPolicy to verify the deletion result​
try {​
console.log(​
`Attempt to obtain the policy of the vector bucket ${vectorBucketName} to verify the deletion result, expecting that it may return 404 (Not Found)...`,​
);​
​
const verifyResult = await client.getVectorBucketPolicy({​
vectorBucketName,​
accountId,​
});​
​
console.log("Verification request successful (policy still exists):");​
console.log(" Request ID:", verifyResult.requestId);​
console.log(" Status Code:", verifyResult.statusCode);​
console.log(" Headers:", verifyResult.headers);​
console.log(" Data (GetVectorBucketPolicyOutput):", verifyResult.data);​
} catch (error: any) {​
// All exceptions, including 404, are handled uniformly through handleError​
handleError(error);​
}​
}​
​
main();​
​
​
Related documentation​
For the API documentation of DeleteVectorBucketPolicy, see DeleteVectorBucketPolicy.​
​
Last updated: 2026.02.06 18:01:44