'AWS-SDK for JavaScript, Getting SecretValue
Basically I have a Lambda function that I'm trying to get some credentials for using Secrets Manager. I feel like I'm missing something silly here but no matter what I try I either get a timeout or the client block never even runs.
exports.handler = async (event, context) => {
const {
SecretsManagerClient,
GetSecretValueCommand
} = require("@aws-sdk/client-secrets-manager");
const client = new SecretsManagerClient({ region: "us-east-1" });
const command = new GetSecretValueCommand({
SecretId: "arn:aws:secretsmanager:us-east-1:my-secret-arn"
});
client.send(command).then(
(data) => {
console.log("Maybe?");
console.log(data.SecretString);
},
(error) => {
console.error(error);
}
);
const response = {
statusCode: 200
};
return response;
};
Solution 1:[1]
Does your lambda have the appropriate policy in its execution role? The SDK may return you a misleading error (i.e. CredentialsError) when you don't have the right policy in place.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | palcina |
