Although AWS officially supports RDS Proxy for Aurora Serverless v2, Laravel Vapor does not natively support this feature. However, you can manually configure RDS Proxy to work with Laravel Vapor. This guide will walk you through the process, ensuring you can leverage RDS Proxy for enhanced database connection management.
1. AWS RDS Proxy and Laravel Vapor
According to the AWS documentation, RDS Proxy is supported for Aurora Serverless v2. However, Laravel Vapor’s documentation does not reflect this capability, and the support team has confirmed that Vapor does not support proxies on Serverless v2 out of the box. This discrepancy means you need to configure the RDS Proxy manually.
2. Manual Configuration of RDS Proxy
Follow these steps to manually set up RDS Proxy for your Laravel Vapor application:
2.1. Update vapor.yml
First, remove the database configuration from your vapor.yml
file:
database: db-name
2.2. Create a New Secret in AWS Secrets Manager
Create a new secret in AWS Secrets Manager with the following details:
- Type: Credentials for RDS database
- Username and Password: Use the credentials you normally use for your database connection (e.g.,
vapor
andpassword
). - Encryption Key: Set to
aws/secretsmanager
. - Database Selection: Choose the database you intend to use the proxy for, matching the username and password provided.
2.3. Create the RDS Proxy
Set up the RDS Proxy in AWS:
- IAM Role: Select
laravel-vapor-role
(the same role used for other Vapor configurations). - Secrets: Use the secret created in step 2.2.
- Transport Layer Security: Enable it.
- Keep other settings at their default values.
2.4. Provision the RDS Proxy
Wait for the RDS Proxy to be fully provisioned. Note that it may appear ready after about 10 minutes, but allow some extra time to ensure it’s fully operational. Once provisioned, note the endpoint URL for the read/write connection.
2.5. Update Vapor Environment Variables
Edit your environment variables in Vapor to use the new RDS Proxy:
DB_HOST=rds-proxy-url-you-got-on-step-4
DB_PORT=3306
DB_DATABASE=vapor
DB_USERNAME=db-username-you-provided-on-step-2
DB_PASSWORD=db-password-you-provided-on-step-2
2.6. Deploy Your Laravel Application
Deploy your application. This deployment should reflect the removal of the database from the vapor.yml
file and use the database connection provided in the environment variables.
Conclusion
By following these steps, you can successfully integrate AWS RDS Proxy with Laravel Vapor, taking advantage of the enhanced connection pooling and improved performance that RDS Proxy offers. This manual setup allows you to bypass the current limitations in Vapor’s native support and ensures your application remains scalable and robust.
If you want to level up your apps and your codebase, check out other posts on our blog igloo.hr.
For further assistance with Laravel Vapor RDS Proxy for AWS Aurora Serverless v2, Laravel development or integrating AWS services, feel free to contact us at [email protected].
Good luck with your deployment!