如何解决NodeJS aws-sdk SecretsManager仅在Ubuntu上抛出ERR_INVALID_ARG_TYPE
以下代码可在Mac上运行,但会在Ubuntu 20.04 ec2实例上抛出
const { SecretsManager } = require('aws-sdk');
(async () => {
const secrets = new SecretsManager({ apiVersion: '2017-10-17',region: 'us-west-2' });
try {
const { SecretString } = await secrets.getSecretValue({ SecretId: 'some-secret-id' }).promise();
console.log(SecretString);
} catch (error) {
console.error(error);
}
})();
操作系统:Ubuntu 20.04
节点:v12.18.3
工作机:
作业系统:macOS 10.15.6
节点:v12.16.1
它也可以在使用最新的NodeJS 12.x版本的Docker中工作
错误:
TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type string or an instance of Buffer,TypedArray,DataView,or KeyObject. Received undefined
at prepareSecretKey (internal/crypto/keys.js:304:11)
at new Hmac (internal/crypto/hash.js:113:9)
at Object.createHmac (crypto.js:143:10)
at Object.hmac (/var/app/tst/node_modules/aws-sdk/lib/util.js:423:30)
at Object.getSigningKey (/var/app/tst/node_modules/aws-sdk/lib/signers/v4_credentials.js:62:8)
at V4.signature (/var/app/tst/node_modules/aws-sdk/lib/signers/v4.js:98:36)
at V4.authorization (/var/app/tst/node_modules/aws-sdk/lib/signers/v4.js:93:36)
at V4.addAuthorization (/var/app/tst/node_modules/aws-sdk/lib/signers/v4.js:35:12)
at /var/app/tst/node_modules/aws-sdk/lib/event_listeners.js:242:18
at finish (/var/app/tst/node_modules/aws-sdk/lib/config.js:386:7) {
code: 'ERR_INVALID_ARG_TYPE',retryDelay: 20.307687997107028
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。