Skip to content

Instantly share code, notes, and snippets.

@leongkui
Created May 23, 2024 08:33
Show Gist options
  • Save leongkui/711b236e879559667dc4c59435b717d0 to your computer and use it in GitHub Desktop.
Save leongkui/711b236e879559667dc4c59435b717d0 to your computer and use it in GitHub Desktop.
AWS Secret Manager - Sample code - JS
// Use this code snippet in your app.
// If you need more information about configurations or implementing the sample code, visit the AWS docs:
// https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/getting-started.html
import {
SecretsManagerClient,
GetSecretValueCommand,
} from "@aws-sdk/client-secrets-manager";
const secret_name = "docdb/master/password";
const client = new SecretsManagerClient({
region: "ap-southeast-1",
});
let response;
try {
response = await client.send(
new GetSecretValueCommand({
SecretId: secret_name,
VersionStage: "AWSCURRENT", // VersionStage defaults to AWSCURRENT if unspecified
})
);
} catch (error) {
// For a list of exceptions thrown, see
// https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html
throw error;
}
const secret = response.SecretString;
// Your code goes here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment