/aws-ssm-parameters-loader-php

Load values from AWS SSM Parameter store into environment variables

Primary LanguagePHPMIT LicenseMIT

AWS SSM Parameters loader for PHP

Latest License PHP Test codecov


Load values from AWS SSM Parameter store into environment variables for Laravel

Installation

composer require sunaoka/aws-ssm-parameters-loader-php

Usage

Create a SSM Parameter

aws ssm put-parameter --name '/path/to/value' --type String --value 'my secret value'

Example 1

use Aws\Ssm\SsmClient;
use Sunaoka\SsmParametersLoader\ParametersLoader;

putenv('MY_PARAMETER=ssm:/path/to/value')

$client = new SsmClient([
    // arguments
]);

$loader = new ParametersLoader($client, 'ssm:');
$loader->load();

echo env('MY_PARAMETER');
// my secret value

Example 2

use Aws\Ssm\SsmClient;
use Sunaoka\SsmParametersLoader\ParametersLoader;

putenv('MY_PARAMETER=ssm:/path/to/value')

$client = new SsmClient([
    // arguments
]);

$loader = new ParametersLoader($client, 'ssm:');
$result = $loader->getParameters();

var_dump($result);
// array(1) {
//   'MY_PARAMETER' =>
//   string(15) "my secret value"
// }