for security reasons I have to store my DB credentials on AWS secret manager so, for this I use the app\Providers\AppServiceProvider.php to connect to aws service with this code
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Config;
...
$client = new Client();
$apiKey = "my-api-key";
$response = $client->request('GET', 'my-credential-aws-url', [
'headers' => [
'X-API-Key' => $apiKey
],
]);
$data = json_decode($response->getBody()->getContents());
Config::set('database.connections.mysql.host', $data->DB_HOST);
Config::set('database.connections.mysql.database', $data->DB_DATABASE);
Config::set('database.connections.mysql.username', $data->DB_USERNAME);
Config::set('database.connections.mysql.password', $data->DB_PASSWORD);
I can get the credentials without problems, but every time that I make a backend api request laravel connect to aws to check the credential even if its loaded, also I added a config to indicate that the creddentials are loadeded Config::set('app.config', true); then check if is necesary load again but dont saves the config.
Do I have to put the code somewhere else?Or how can I configure it to only connect to AWS once?
Httpfacade, you will not need to dojson_decode. Second, could you show us where you are doingConfig::setand when doesConfig::getget triggered?