constup/aws-secrets-bundle
Symfony bundle that loads parameters from AWS Secrets Manager into the service container. Supports Symfony 5/6 (v1/v2) and requires aws/aws-sdk-php. Configure region/credentials and reference secrets in config for environment-specific setups.
The constup/aws-secrets-bundle is Symfony-centric but can be leveraged in Laravel due to Laravel’s reliance on Symfony components (e.g., Dependency Injection, HttpClient). Key fit considerations:
%env(aws:...)% syntax integrates with Laravel’s container via Symfony’s parameter bag, enabling zero-code changes for basic use cases (e.g., replacing .env variables).config/packages/, requiring Laravel to adapt (e.g., via config/aws_secrets.php).env() Helper: The bundle doesn’t natively extend Laravel’s env() function, necessitating custom logic (e.g., a service provider) to bridge %env(aws:...)% with Laravel’s environment system.php artisan aws:secrets:list), requiring manual AWS CLI usage or custom commands.aws/aws-sdk-php to avoid conflicts. Use composer require aws/aws-sdk-php:^3.0 and configure the bundle to reuse the existing SDK instance.symfony/dependency-injection:^5.3 for v1.x).config/aws_secrets.php to mirror Symfony’s YAML config:
return [
'client_config' => [
'region' => env('AWS_REGION'),
'credentials' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
],
],
'cache' => env('AWS_SECRETS_CACHE', 'array'),
'ignore' => env('AWS_SECRETS_IGNORE', false),
];
%env(aws:...)% in Laravel’s container:
use Constup\AwsSecretsBundle\DependencyInjection\AwsSecretsExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class AwsSecretsServiceProvider extends ServiceProvider {
public function register() {
$this->app->singleton('aws.secrets', function () {
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
$loader->load('aws_secrets.php');
$extension = new AwsSecretsExtension();
$extension->load([], $container);
return $container->get('aws_secrets.client');
});
}
}
.env: Replace hardcoded secrets with AWS references (e.g., DB_PASSWORD=%env(aws:RDS_PASSWORD)%).DATABASE_URL format.%env(aws:...)%.ignore: true in config to bypass AWS calls locally, but ensure secrets are still available via .env or another fallback.aws/aws-sdk-php? If so, how can the bundle reuse it to avoid duplication?%env(aws:...)% be resolved in Laravel’s env() helper or Blade templates? Will a custom resolver be needed?filesystem) mitigate this?array caching for local testing, but CI/CD may need a different approach.dev-db-password, prod-db-password)? Will AWS Secret names include environment prefixes?.env or a default value?constup/aws-secrets-bundle:^1) for Symfony 5.3+ compatibility.aws/aws-sdk-php:^3.0 is installed and configured to avoid conflicts with Laravel’s dependencies.constup/aws-secrets-bundle:^2) for Symfony 6.0+ compatibility.HttpClient; ensure Laravel’s symfony/http-client is aligned with the bundle’s version.Pre-Migration:
.env, config files, or code.secretsmanager:GetSecretValue permissions..env (e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION).Bundle Installation:
composer require constup/aws-secrets-bundle:^1 # For Laravel 9.x
composer require constup/aws-secrets-bundle:^2 # For Laravel 10.x
composer require aws/aws-sdk-php:^3.0
Configuration:
config/aws_secrets.php:
return [
'client_config' => [
'region' => env('AWS_REGION'),
'credentials' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
],
'version' => 'latest',
],
'cache' => env('AWS_SECRETS_CACHE', 'array'), // Use 'filesystem' for local dev
'delimiter' => ',',
'ignore
How can I help you explore Laravel packages today?