vlucas / phpdotenv

Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.
BSD 3-Clause "New" or "Revised" License
13.15k stars 626 forks source link

Load AWS system environments #557

Closed celsomtrindade closed 11 months ago

celsomtrindade commented 1 year ago

Is it possible to load AWS environment variables with this lib?

I used to use .env file, but on AWS they have these variables which seems to be best choice, specially because of my CI/CD worflow. Now I want to load from AWS Secrets Manager.

The way I was able to make it work, at least for now, was to disable the usage of this lib and directly use getenv().

Thanks

GrahamCampbell commented 11 months ago

I don't understand what your question is here?

GrahamCampbell commented 11 months ago

(FYI getenv is almost always the wrong choice, and will be broken if you are using php-fpm, for ~1-0.01% of requests, depending on server setup due to concurrency bugs - getenv is not threadsafe)

frob commented 11 months ago

I think the issue is that the aws sdk uses getenv to load the aws system credentials. The solution, I think is to load the credentials manually or, if your code is hosted on aws ec2, to use an ec2 role to provide access.

GrahamCampbell commented 11 months ago

You can request that we use getenv and putenv as per https://github.com/vlucas/phpdotenv?tab=readme-ov-file#putenv-and-getenv