December 1, 2023

To integrate AWS Secret Manager with PHP using IAM role, you need to do the following:

Create an IAM role with the following permissions:

Attach the IAM role to your PHP application.

In your PHP code, use the AWS SDK for PHP to get the secret value from Secrets Manager.

Here is an example of how to do this:

require ‘vendor/autoload.php’;
use Aws\SecretsManager\SecretsManagerClient;

// Create a SecretsManagerClient object
$client = new SecretsManagerClient([
‘profile’ => ‘default’,
‘version’ => ‘latest’,
‘region’ => ‘us-east-1’,

// Get the secret value
$secretName = ‘my-secret’;
$result = $client->getSecretValue([
‘SecretId’ => $secretName,

// Get the secret value from the result
$secret = $result[‘SecretString’];

// Use the secret
echo $secret;

In this example, we are assuming that the IAM role has already been created and attached to the PHP application. We are also assuming that the secret name is my-secret. The getSecretValue method will return the secret value as a string. We can then use the secret value in our PHP code.

For more information on how to integrate AWS Secret Manager with PHP, please refer to the following documentation:

AWS Secrets Manager documentation:
AWS SDK for PHP documentation:

Leave a Reply

Your email address will not be published. Required fields are marked *