php-awsHow do I use AWS Secrets Manager with PHP?
Using AWS Secrets Manager with PHP is easy. You can use the AWS SDK for PHP to access the Secrets Manager service.
The following example code block shows how to retrieve a secret value using the getSecretValue
method of the Aws\SecretsManager\SecretsManagerClient
class:
<?php
use Aws\SecretsManager\SecretsManagerClient;
$client = new SecretsManagerClient([
'region' => 'us-east-1',
'version' => 'latest',
]);
$secretValue = $client->getSecretValue([
'SecretId' => 'my-secret',
]);
echo $secretValue['SecretString'];
This code will output the secret value stored in the my-secret
secret.
Code explanation
use Aws\SecretsManager\SecretsManagerClient;
- imports theSecretsManagerClient
class.$client = new SecretsManagerClient([
- creates a newSecretsManagerClient
instance.'SecretId' => 'my-secret'
- specifies the name of the secret to retrieve.$secretValue = $client->getSecretValue([
- calls thegetSecretValue
method to retrieve the secret value.echo $secretValue['SecretString'];
- outputs the secret value.
For more information, please refer to the AWS Secrets Manager documentation.
More of Php Aws
- How can I use PHP to connect to an Amazon Aurora database?
- How do I use PHP to create a ZIP file on AWS?
- How can I use the AWS API Gateway with PHP?
- How can I use AWS and Zksync together with PHP?
- How can I use Yum to install PHP on an Amazon EC2 instance?
- How can I use an AWS SQS Worker with PHP?
- How can I use AWS WAF to secure my PHP application?
- How can I use AWS PHP SDK without credentials?
- How do I generate an AWS Signature Version 4 with PHP?
- How do I determine the version of PHP I am running on AWS?
See more codes...