Created
October 19, 2019 00:11
-
-
Save msato0731/5be8268f223b528f45fad6ed1fb6f61f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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