sunaoka/aws-ssm-parameters-loader-php

Load values from AWS SSM Parameter store into environment variables

v1.0.2 2024-12-12 09:37 UTC

This package is auto-updated.

Last update: 2024-12-12 09:38:11 UTC


README

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"
// }