📢 Registration + agenda now live
Explore the latest Grafana Cloud and AI solutions, learn tips & tricks from demos and hands-on workshops, and get actionable advice to advance your observability strategy. Register now and get 50% off - limited tickets available (while they last!).
SecretsManagerClient interacts with the AWS Secrets Manager.
With it, you can perform several operations such as listing, creating and downloading secrets owned by the authenticated user. For a full list of supported operations, see Methods.
SecretsManagerClient is included in both the dedicated jslib secrets-manager.js bundle, and the aws.js one, containing all the services clients.
S3 Client methods will throw errors in case of failure.
Error
Condition
InvalidSignatureError
when invalid credentials were provided.
SecretsManagerServiceError
when AWS replied to the requested operation with an error.
Example
JavaScript
import exec from'k6/execution';import{
AWSConfig,
SecretsManagerClient,}from'https://jslib.k6.io/aws/0.14.0/secrets-manager.js';const awsConfig =newAWSConfig({region: __ENV.AWS_REGION,accessKeyId: __ENV.AWS_ACCESS_KEY_ID,secretAccessKey: __ENV.AWS_SECRET_ACCESS_KEY,});const secretsManager =newSecretsManagerClient(awsConfig);const testSecretName ='jslib-test-secret';const testSecretValue ='jslib-test-value';exportasyncfunctionsetup(){// Let's make sure our test secret is createdconst testSecret =await secretsManager.createSecret(
testSecretName,
testSecretValue,'this is a test secret, delete me.');// List the secrets the AWS authentication configuration// gives us access to, and verify the creation was successful.const secrets =await secretsManager.listSecrets();if(!secrets.filter((s)=> s.name === testSecret.name).length ==0){
exec.test.abort('test secret not found');}}exportdefaultasyncfunction(){// Knnowing that we know the secret exist, let's update its valueconst newTestSecretValue ='new-test-value';await secretsManager.putSecretValue(testSecretName, newTestSecretValue);// Let's get its value and verify it was indeed updatedconst updatedSecret =await secretsManager.getSecret(testSecretName);if(updatedSecret.secret !== newTestSecretValue){
exec.test.abort('unable to update test secret');}// Let's now use our secret in the context of our load test...}exportasyncfunctionteardown(){// Finally, let's clean after ourselves and delete our test secretawait secretsManager.deleteSecret(testSecretName,{noRecovery:true});}