SecretsManager client

This page contains examples with the SecretsManager 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 SecretsManager package could be installed with Composer.

composer require async-aws/secrets-manager

A new client object may be instantiated by:

use AsyncAws\SecretsManager\SecretsManagerClient; $secretsManager = new SecretsManagerClient();

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

use AsyncAws\SecretsManager\SecretsManagerClient; $secretsManager = new SecretsManagerClient([ '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; $secretsManager = new SecretsManagerClient(); $input = new CreateSecretRequest([ 'Name' => 'keyName', 'Description' => 'Test description', 'SecretString' => 'secretValue', ]); $result = $secretsManager->CreateSecret($input); $result->resolve();

Update secret

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

Update secret value

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

Delete secret

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

Get secret

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

List secrets

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

The source code to this page is found on GitHub.