Volcano Engine OpenAPI node sdk
中文文档
Requirements:
Installation
npm install -S @volcengine/openapi
Basic Usage
1. Setting OpenAPI service's AK&SK
Available in three settings
1. Use API to set AK&SK
const iamService = iam.defaultService;
iamService.setAccessKeyId(AccessKeyId);
iamService.setSecretKey(SecretKey);
iamService.setSessionToken(SessionToken);
2. Use environment variables to set AK & SK
VOLC_ACCESSKEY="your ak" VOLC_SECRETKEY="your sk"
3. Use configuration file
Put it in ~/.volc/config
in json format, the format is:
{"VOLC_ACCESSKEY":"your ak","VOLC_SECRETKEY":"your sk"}
Request OpenAPI
Take the ListUsers API of the iam service as an example
import { iam } from'@volcengine/openapi';
async function main(AccessKeyId, SecretKey) {
const iamService = iam.defaultService;
iamService.setAccessKeyId(AccessKeyId);
iamService.setSecretKey(SecretKey);
const usersResponse = await iamService.ListUsers({
Limit: 10,
Offset: 0,
});
}
OpenAPI signature method
import {Signer} from '@volcengine/openapi';
const openApiRequestData: RequestObj = {
region: 'cn-north-1',
method: 'GET',
params: {},
headers: {},
body: "",
}
const signer = new Signer(openApiRequestData, "iam");
signer.addAuthorization({accessKeyId, secretKey, sessionToken});
console.log(openApiRequestData.headers);
By HTTP Query
const openApiRequestData: RequestObj = {
method: "POST",
region: "cn-north-1",
params: {
Action: "AssumeRole",
Version: "2018-01-01",
RoleTrn: "trn:iam::200:role/STSRole",
RoleSessionName: "test",
},
}
const credentials: Credentials = {
accessKeyId: VOLC_ACCESSKEY,
secretKey: VOLC_SECRETKEY,
sessionToken: "",
}
const signer = new Signer(openApiRequestData, "sts");
const signedQueryString = signer.getSignUrl(credentials);