SecretManager client

This page contains examples with the SecretManager client. See the client introduction for a more detailed description how to use a client. You may also want to consider the authentication documentation to understand the many ways you can authenticate with AWS.

The SecretManager package could be installed with Composer.

composer require async-aws/secrets-manager

A new client object may be instantiated by:

use AsyncAws\SecretManager\SecretManagerClient; $secretManager = new SecretManagerClient();

The authentication parameters is read from the environment by default. You can also specify a AWS access id and secret:

use AsyncAws\SecretManager\SecretManagerClient; $secretManager = new SecretManagerClient([ 'accessKeyId' => 'my_access_key', 'accessKeySecret' => 'my_access_secret', 'region' => 'eu-central-1', ]);

For all available options, see the configuration reference.

Usage

Create secret

use AsyncAws\SecretsManager\Input\CreateSecretRequest; use AsyncAws\SecretsManager\SecretsManagerClient; $secretManager = new SecretsManagerClient(); $input = new CreateSecretRequest([ 'Name' => 'keyName', 'Description' => 'Test description', 'SecretString' => 'secretValue', ]); $result = $secretManager->CreateSecret($input); $result->resolve();

Update secret

use AsyncAws\SecretsManager\Input\PutSecretValueRequest; use AsyncAws\SecretsManager\SecretsManagerClient; $secretManager = new SecretsManagerClient(); $input = new PutSecretValueRequest([ 'SecretId' => 'keyName', 'SecretString' => 'testPutSecret', ]); $result = $secretManager->PutSecretValue($input); $result->resolve();

Update secret value

use AsyncAws\SecretsManager\Input\UpdateSecretRequest; use AsyncAws\SecretsManager\SecretsManagerClient; $secretManager = new SecretsManagerClient(); $input = new UpdateSecretRequest([ 'SecretId' => 'keyName', 'Description' => 'New description', ]); $result = $secretManager->updateSecret($input); $result->resolve();

Delete secret

use AsyncAws\SecretsManager\SecretsManagerClient; $secretManager = new SecretsManagerClient(); $result = $secretManager->deleteSecret([ 'SecretId' => 'keyName', ]); $result->resolve();

Get secret

use AsyncAws\SecretsManager\SecretsManagerClient; $secretManager = new SecretsManagerClient(); $entry = $secretManager->getSecretValue([ 'SecretId' => 'keyName', ]); echo $entry->getSecretString();

List secrets

use AsyncAws\SecretsManager\SecretsManagerClient; use AsyncAws\SecretsManager\ValueObject\SecretListEntry; $secretManager = new SecretsManagerClient(); $secrets = $secretManager->listSecrets(); /** @var SecretListEntry $entry */ foreach ($secrets as $entry) { echo $entry->getName(); }

The source code to this page is found on GitHub.