CueTracker's avatar

Environment vars from AWS Secrets Manager

Hi,

I have my app's environment-vars stored in AWS Secrets Manager. These get loaded into my current (raw PHP) application from the task definition when the Docker containers get deployed to ECS. I'm going to switch to Laravel, but can't figure out how to load in these env-vars, as there won't be a .env-file. Would I need to create an empty file during the deploy, and the app takes the values using getenv()? Is there a standard way to handle secrets for a Laravel app when using AWS ECS containers?

0 likes
5 replies
martinbean's avatar

@cuetracker An .env file is just a replacement for actual environment variables. So just load the secrets as actual environment variables and your application will read them just fine.

1 like
madsynn's avatar

@martinbean I am also working with secrets manager and i am trying to load the variables like normal but its not pulling them into the places it needs them. do we need to change the way they are retrieved. I have tried the following.

  • getenv('KEY')
  • env('KEY')
  • print_r($_ENV[KEY])

None of these seem to work. Any help would be great on this.

zvermafia's avatar

@madsynn fetch the secrets and set them via Env::getRepository()->set('KEY', 'Totally secret value') and you will get what you set when call env('KEY')

Please or to participate in this conversation.