Created
May 24, 2022 15:01
-
-
Save jklingsporn/32d7d2b64c8ab1532d5d95fb3248a4c8 to your computer and use it in GitHub Desktop.
Creates a Symfony .env.local-File based on ElasticBeanstalk's environment variables. Comes in handy when running outside the container (e.g. cronjobs)
This file contains 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
#this goes into .ebextensions-Folder | |
files: | |
"/var/app/current/.env.local" : | |
mode: "000644" | |
owner: root | |
group: root | |
content: | | |
NO_SUCH_KEY=NO_SUCH_VALUE | |
container_commands: | |
create_env_local: | |
command: "php /var/app/staging/create_env_local.php" |
This file contains 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 | |
$aws_env = shell_exec('/opt/elasticbeanstalk/bin/get-config environment'); | |
if($aws_env){ | |
$myfile = fopen(".env.local", "w") or die("Unable to open file!"); | |
$aws_env_arr = json_decode($aws_env); | |
echo "Adding\n"; | |
foreach ($aws_env_arr as $key=>$value) { | |
$line = "$key=$value\n"; | |
echo "$line"; | |
fwrite($myfile, $line); | |
} | |
fclose($myfile); | |
}else{ | |
echo "Environment variables not found"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment