在 Node.js 中注册证书包 - Amazon SDK for JavaScript
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

Amazon SDK for JavaScript V3 API 参考指南详细描述了 Amazon SDK for JavaScript 版本 3 (V3) 的所有 API 操作。

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

在 Node.js 中注册证书包

Node.js 的默认信任存储包含访问 Amazon 服务所需的证书。在某些情况下,最好只包括一组特定的证书。

在本示例中,使用磁盘上的特定证书创建 https.Agent,除非提供指定的证书,否则它会拒绝连接。然后,DynamoDB 客户端将使用新创建的 https.Agent

import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { NodeHttpHandler } from "@smithy/node-http-handler"; import { Agent } from "https"; import { readFileSync } from "fs"; const certs = [readFileSync("/path/to/cert.pem")]; const agent = new Agent({ rejectUnauthorized: true, ca: certs }); const dynamodbClient = new DynamoDBClient({ requestHandler: new NodeHttpHandler({ httpAgent: agent, httpsAgent: agent }) });