You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Node API创建Bastion端口转发会话遇Missing Parameter错误求助

OCI TypeScript SDK创建Bastion端口转发会话报"Missing Parameter"错误排查

我参考官方示例创建Bastion端口转发会话时,收到错误提示errorObject: OciError: Missing Parameter。通过CLI使用相同参数可成功创建会话,但用Node.js API实现时出现该问题。以下是代码片段及错误响应:

代码片段

const provider = new common.ConfigFileAuthenticationDetailsProvider();

const bastionClient = new bastion.BastionClient({ authenticationDetailsProvider: provider });

// 创建目标资源详情对象
const fileContent = fs.readFileSync(filePath, 'utf8');
const targetResourceDetails = JSON.parse(fileContent);

// 创建请求及依赖对象
const createSessionDetails = {
  displayName: "Session-" + user.toLowerCase() + "-" + portStart + "-" + new Date().toISOString().slice(0, 16).replace(/[-:T]/g, ""),
  bastionId: BASTIONID,
  targetResourceDetails: targetResourceDetails,
  keyType: bastion.models.CreateSessionDetails.KeyType.Pub,
  keyDetails: {
    publicKeyContent: "ssh-rsa …"
  },
  sessionTtlInSeconds: 10800
};

console.log("req: ", createSessionDetails);

// 创建会话
const createSessionRequest = bastion.requests.CreateSessionRequest = {
  createSessionDetails: JSON.stringify(createSessionDetails)
};

const createSessionResponse = await bastionClient.createSession(createSessionRequest);

错误响应

error from defaultErrorFunction: {
  response: Response {
    [Symbol(realm)]: null,
    [Symbol(state)]: {
      aborted: false,
      rangeRequested: false,
      timingAllowPassed: true,
      requestIncludesCredentials: true,
      type: 'default',
      status: 400,
      timingInfo: [Object],
      cacheState: '',
      statusText: 'Bad Request',
      headersList: [HeadersList],
      urlList: [Array],
      body: [Object]
    },
    [Symbol(headers)]: HeadersList {
      cookies: null,
      [Symbol(headers map)]: [Map],
      [Symbol(headers map sorted)]: null
    }
  },
  errorObject: OciError: Missing Parameter
  at Object.handleErrorResponse (/tmp/pfw-oci/node_modules/oci-common/lib/helper.js:34:16)
  at Function.<anonymous> (/tmp/pfw-oci/node_modules/oci-common/lib/circuit-breaker.js:30:50)
  at Generator.next (<anonymous>)
  at fulfilled (/tmp/pfw-oci/node_modules/oci-common/lib/circuit-breaker.js:9:58)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
    statusCode: 400,
    serviceCode: 'MissingParameter',
    opcRequestId: '…',
    targetService: 'Bastion',
    operationName: 'createSession',
    timestamp: '2023-10-01T22:33:48.055Z',
    requestEndpoint: 'POST https://bastion.ap-singapore-1.oci.oraclecloud.com/20210331/sessions',
    clientVersion: 'Oracle-TypeScriptSDK/2.70.1',
    loggingTips: 'To get more info on the failing request, refer to https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/typescriptsdkconcepts.htm#typescriptsdkconcepts_topic_Logging for ways to log the request/response details.',
    troubleshootingTips: "See https://docs.oracle.com/iaas/Content/API/References/apierrors.htm#apierrors_400__400_missingparameter for more information about resolving this error Also see https://docs.oracle.com/iaas/api/#/en/bastion/20210331/Session/CreateSession for details on this operation's requirements. If you are unable to resolve this Bastion issue, please contact Oracle support and provide them this full error message."
  }
}

问题排查及解决方案

错误根源在于手动将createSessionDetails序列化为JSON字符串。OCI TypeScript SDK会自动处理请求体的序列化工作,手动转成字符串后,服务端无法正确解析参数结构,从而触发"Missing Parameter"错误。

修改请求创建代码,直接传入对象而非JSON字符串:

// 修正后的请求创建代码
const createSessionRequest: bastion.requests.CreateSessionRequest = {
  createSessionDetails: createSessionDetails
};

// 或使用对象简写语法
const createSessionRequest: bastion.requests.CreateSessionRequest = {
  createSessionDetails
};

修改后重新调用bastionClient.createSession即可正常创建会话。

内容的提问来源于stack exchange,提问作者Rima

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 10:25:31