Skip to content

Instantly share code, notes, and snippets.

@msato0731
Created October 19, 2019 00:11
Show Gist options
  • Save msato0731/5be8268f223b528f45fad6ed1fb6f61f to your computer and use it in GitHub Desktop.
Save msato0731/5be8268f223b528f45fad6ed1fb6f61f to your computer and use it in GitHub Desktop.
<?php
require 'vendor/autoload.php';
function getSsmParameter($paths)
{
$sharedConfig = [
'region' => 'ap-northeast-1',
'version' => 'latest'
];
$client = new Aws\Ssm\SsmClient($sharedConfig);
$result = $client->getParametersByPath(
[
'Path' => $paths,
'WithDecryption' => true
]
);
$count = 0;
foreach ($result['Parameters'] as $v) {
$name = $v['Name'];
$params[$name] = $v['Value'];
$param_name = explode('/', $name);
$env_values[$count] = $param_name[3] . "=" . $params[$name];
$count++;
}
return $env_values;
}
$env_values = getSsmParameter('/MyService/Test/');
$fp = fopen(".env", "w");
foreach ($env_values as $v){
fwrite($fp, $v);
fwrite($fp, "\n");
}
fclose($fp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment