Skip to content

Instantly share code, notes, and snippets.

@jklingsporn
Created May 24, 2022 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jklingsporn/32d7d2b64c8ab1532d5d95fb3248a4c8 to your computer and use it in GitHub Desktop.
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 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"
<?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