Reputation: 729
Below is the code that I'm running via a Lambda function with full SecretsManagerReadWrite permission on its role:
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");
}
}
You can see clearly that I am passing secretId as a parameter to the command sent via the secrets manager client, however this error occurs:
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
}
}
I don't know where else it could be expecting the member 'secretId' as I've tried passing it as a configuration param when initialising SecretsManager, and the docs for API V3 don't suggest anywhere else either.
Any help would be greatly appreciated!
Upvotes: 2
Views: 8779
Reputation: 10724
For future reference - AWS SDK V3 SecretsManager code examples can be found here:
https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javascriptv3/example_code/secrets-manager
Upvotes: 2
Reputation: 729
I've solved the issue (typical that it's minutes after posting)
The error states that it's expecting a member with key 'secretId', however it needs to be passed as 'SecretId' - note the uppercase first character
After changing the param passed to the constructor of the command to be the latter key, it now works...
Upvotes: 3