snippets_js
Integration
New integration from credential
const awsSecretsManagerClient = yepcode.integration.awsSecretsManager("credential-slug");
New integration from plain authentication data
const { SecretsManagerClient } = require("@aws-sdk/client-secrets-manager");
const awsSecretsManagerClient = new SecretsManagerClient({
credentials: {
accessKeyId: "accessKeyId",
secretAccessKey: "secretAccessKey",
},
});
Create Secret
Create secret
const { CreateSecretCommand } = require("@aws-sdk/client-secrets-manager");
const createSecretCommand = new CreateSecretCommand({
Name: "secret-name",
SecretString: "secret-to-store",
});
awsSecretsManagerClient.send(createSecretCommand).then((response) => {
console.log(`Created secret with name ${response.Name}`);
}).catch(console.error);
List Secrets
List secrets
const { ListSecretsCommand } = require("@aws-sdk/client-secrets-manager");
const listSecretsCommand = new ListSecretsCommand({});
awsSecretsManagerClient.send(listSecretsCommand).then((response) => {
const secrets = response.SecretList;
secrets.forEach((secret) => console.log(`Found secret with name ${secret.Name}`));
}).catch(console.error);
Get Secret Value
Get secret value
const { GetSecretValueCommand } = require("@aws-sdk/client-secrets-manager");
const getSecretValueCommand = new GetSecretValueCommand({
SecretId: "secret-name-or-ARN"
});
awsSecretsManagerClient.send(getSecretValueCommand).then((response) => {
// Secret value comes in response.SecretString or response.SecretBinary
// If you store other types of secrets different than key value pairs,
// then it will come as a JSON string
}).catch(console.error);
Delete Secret
Delete secret
const { DeleteSecretCommand } = require("@aws-sdk/client-secrets-manager");
const deleteSecretCommand = new DeleteSecretCommand({
SecretId: "secret-name-or-ARN"
});
awsSecretsManagerClient.send(deleteSecretCommand).then((response) => {
console.log(`Deleted secret with name ${response.Name}`);
}).catch(console.error);