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

使用@aws-sdk/client-secrets-manager时遇SecretString读取错误如何解决?

解决@aws-sdk/client-secrets-manager中"Cannot read properties of undefined (reading 'SecretString')"错误

当你使用@aws-sdk/client-secrets-manager操作AWS密钥管理器时,如果遇到Cannot read properties of undefined (reading 'SecretString')的报错,最直接的解决方案就是更新你的@aws-sdk/client-secrets-manager依赖到最新版本。

这个报错大多是因为旧版本SDK在处理返回值结构时存在逻辑问题,导致尝试读取SecretString时对应的对象为undefined。新版本的SDK已经修复了这个解析bug,更新后就能正常访问SecretString字段。

举个简单的代码示例,更新后你可以正常使用以下逻辑获取密钥:

import { SecretsManagerClient, GetSecretValueCommand } from "@aws-sdk/client-secrets-manager";

const client = new SecretsManagerClient({ region: "us-east-1" });
const command = new GetSecretValueCommand({ SecretId: "your-secret-id" });
const response = await client.send(command);
const secret = response.SecretString; // 此时不会再出现undefined报错

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 11:28:10