AWS SDK V3 SecretsManager:'secretId' 处的值为 null
AWS SDK V3 SecretsManager: Value null at 'secretId'
下面是我 运行 通过 Lambda 函数编写的代码,对其角色具有完整的 SecretsManagerReadWrite 权限:
const { SecretsManagerClient, GetSecretValueCommand } = require('@aws-sdk/client-secrets-manager');
exports.handler = async () => {
const secretsManagerClient = new SecretsManagerClient({
region: 'eu-west-2'
});
const params = {
secretId: 'Realitex/APIAccount'
}
const command = new GetSecretValueCommand(params);
try {
const data = await secretsManagerClient.send(command);
console.log(data);
} catch (error) {
console.log(error, error.stack);
} finally {
console.log("Done getting");
}
}
您可以清楚地看到,我将 secretId 作为参数传递给通过 secrets manager 客户端发送的命令,但是出现此错误:
2021-03-17T15:20:39.963Z 0bd9bc3a-47ce-4c57-b583-0df9d9d70b34 INFO ValidationException: 1 validation error detected: Value null at 'secretId' failed to satisfy constraint: Member must not be null
at deserializeAws_json1_1GetSecretValueCommandError (/var/task/node_modules/@aws-sdk/client-secrets-manager/dist/cjs/protocols/Aws_json1_1.js:770:41)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async /var/task/node_modules/@aws-sdk/middleware-serde/dist/cjs/deserializerMiddleware.js:6:20
at async /var/task/node_modules/@aws-sdk/middleware-signing/dist/cjs/middleware.js:12:24
at async StandardRetryStrategy.retry (/var/task/node_modules/@aws-sdk/middleware-retry/dist/cjs/defaultStrategy.js:56:46)
at async /var/task/node_modules/@aws-sdk/middleware-logger/dist/cjs/loggerMiddleware.js:6:22
at async Runtime.exports.handler (/var/task/index.js:14:18) {
__type: 'ValidationException',
'$fault': 'client',
'$metadata': {
httpStatusCode: 400,
requestId: '7b22cb52-0345-4c49-bd41-33aa3a1be707',
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
}
}
我不知道它还能在哪里期待成员 'secretId',因为我在初始化 SecretsManager 时尝试将其作为配置参数传递,而 API V3 的文档没有也不推荐其他地方。
如有任何帮助,我们将不胜感激!
我已经解决了这个问题(通常是在发布后几分钟)
错误指出它需要一个具有键 'secretId' 的成员,但它需要作为 'SecretId' 传递 - 注意第一个字符大写
将传递给命令构造函数的参数更改为后一个键后,它现在可以工作了...
供将来参考 - AWS SDK V3 SecretsManager 代码示例可在此处找到:
https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javascriptv3/example_code/secrets
下面是我 运行 通过 Lambda 函数编写的代码,对其角色具有完整的 SecretsManagerReadWrite 权限:
const { SecretsManagerClient, GetSecretValueCommand } = require('@aws-sdk/client-secrets-manager');
exports.handler = async () => {
const secretsManagerClient = new SecretsManagerClient({
region: 'eu-west-2'
});
const params = {
secretId: 'Realitex/APIAccount'
}
const command = new GetSecretValueCommand(params);
try {
const data = await secretsManagerClient.send(command);
console.log(data);
} catch (error) {
console.log(error, error.stack);
} finally {
console.log("Done getting");
}
}
您可以清楚地看到,我将 secretId 作为参数传递给通过 secrets manager 客户端发送的命令,但是出现此错误:
2021-03-17T15:20:39.963Z 0bd9bc3a-47ce-4c57-b583-0df9d9d70b34 INFO ValidationException: 1 validation error detected: Value null at 'secretId' failed to satisfy constraint: Member must not be null
at deserializeAws_json1_1GetSecretValueCommandError (/var/task/node_modules/@aws-sdk/client-secrets-manager/dist/cjs/protocols/Aws_json1_1.js:770:41)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async /var/task/node_modules/@aws-sdk/middleware-serde/dist/cjs/deserializerMiddleware.js:6:20
at async /var/task/node_modules/@aws-sdk/middleware-signing/dist/cjs/middleware.js:12:24
at async StandardRetryStrategy.retry (/var/task/node_modules/@aws-sdk/middleware-retry/dist/cjs/defaultStrategy.js:56:46)
at async /var/task/node_modules/@aws-sdk/middleware-logger/dist/cjs/loggerMiddleware.js:6:22
at async Runtime.exports.handler (/var/task/index.js:14:18) {
__type: 'ValidationException',
'$fault': 'client',
'$metadata': {
httpStatusCode: 400,
requestId: '7b22cb52-0345-4c49-bd41-33aa3a1be707',
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
}
}
我不知道它还能在哪里期待成员 'secretId',因为我在初始化 SecretsManager 时尝试将其作为配置参数传递,而 API V3 的文档没有也不推荐其他地方。
如有任何帮助,我们将不胜感激!
我已经解决了这个问题(通常是在发布后几分钟)
错误指出它需要一个具有键 'secretId' 的成员,但它需要作为 'SecretId' 传递 - 注意第一个字符大写
将传递给命令构造函数的参数更改为后一个键后,它现在可以工作了...
供将来参考 - AWS SDK V3 SecretsManager 代码示例可在此处找到:
https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javascriptv3/example_code/secrets