I have a web application that uses an EC2 instance to receive uploaded images, resize and store on S3 and update my MySQL database with the image record. This database is hosted outside Amazon Web Services and so obviously involves communication between the EC2 instance and the database. Images are posted to the upload server from a Flash client which receives the IP address of the upload server when it is loaded and so sends images to 1.12.23.34/resize_script.php
This has worked great .. until i started to try and include a load balancer.
Since the ELBs do not use an IP address but a DNS address I am now passing this to Flash. Now when I upload images I get the following response from the server -
Could not connect to MySQL: Lost connection to MySQL server at 'reading initial communication packet', system error: 111
What might be causing the lost connection to MySQL server. Is there any additional steps I need to take to allow my upload servers to be load balanced? I have set the host property of my MySQL privileges for this user to %
any pointers greatly appreciated thanks.
Check both the firewall rules and the MySQL user permissions on the database. Does your database server allow incoming connections from the new ELB ip address?
Assign each one of the EC2 instances an Elastic IP, you won't be charged for the Elastic IP's as long as they're assigned to EC2 instances (be sure to delete them when your done with them, ie don't leave them without an instance assigned because for some reason amazon charge for idle Elastic IP's).
Once each EC2 instance has an IP you need to authorise those IP's to connect to the Database server.
It's not the load balancer that connects to the database server (it's the EC2 instances) so you don't need to worry about the ELB's dns or changing ip.
Hope that helps for anyone else stuck with this