I setup secret manager on my local system and now I have .aws directory in my windows root directory. And by using the following code, I am retrieving my access-key-id and value.
client.getSecretValue({SecretId: secretName}, function(err, data) {
// console.log(err);
if (err) {
console.log(err);
if (err.code === 'DecryptionFailureException')
// Secrets Manager can't decrypt the protected secret text using the provided KMS key.
throw err;
else if (err.code === 'InternalServiceErrorException')
// An error occurred on the server side.
throw err;
else if (err.code === 'InvalidParameterException')
// You provided an invalid value for a parameter.
throw err;
else if (err.code === 'InvalidRequestException')
// You provided a parameter value that is not valid for the current state of the resource.
throw err;
else if (err.code === 'ResourceNotFoundException')
// We can't find the resource that you asked for.
throw err;
}
else {
// Decrypts secret using the associated KMS CMK.
// Depending on whether the secret is a string or binary, one of these fields will be populated.
if ('SecretString' in data) {
secret = JSON.parse(data.SecretString);
secretKey = secret["AWS_ACCESS_KEY_ID"];
clientID = secret["AWS_ACCESS_KEY_ID"];
secret.region = "us-east-1";
global.secret = secret;
} else {
let buff = new Buffer(data.SecretBinary, 'base64');
decodedBinarySecret = buff.toString('ascii');
}
// routes
require('./services')(router,validation);
}
});
It is working well. But when I run the above code with docker, it gets failed with following error
Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1.