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:
// 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
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: https://docs.aws.amazon.com/secretsmanager/latest/userguide/
AWS SDK for PHP documentation: https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/