I was wondering if someone could give me some pointers on how I would go about adding AUTO scaling a AWS server that has been set up via Forge. I know how to do it manually with a load balancer and two servers via Forge, but I am not sure how to solve it using the auto scaling of AWS.
Anyone that have got a blog post or clip somewhere that they can recommend watching? :)
As far as I know, Forge does not support it. You can configure your own autoscaling group within AWS and trigger building new servers from an AMI's it is fairly easy to set up in AWS admin panel.
Other than that I have not seen an automated way to do this.
Sure, here's a step-by-step guide to set up auto-scaling for your Laravel application on AWS EC2 instances:
Step 1: Create an Amazon Machine Image (AMI)
Deploy your Laravel application to an EC2 instance using Laravel Forge or manually. Ensure that your application is running correctly on this instance.
In the AWS Management Console, navigate to the EC2 Dashboard.
Locate your running EC2 instance and select it.
From the "Actions" dropdown menu, choose "Create Image".
Provide a name and description for the image, then click "Create Image".
Wait for the image creation process to complete. The new image will be available in the "AMIs" section of the EC2 Dashboard.
Step 2: Set up an Elastic Load Balancer (ELB)
In the AWS Management Console, navigate to the EC2 Dashboard and click on "Load Balancers" in the left sidebar.
Configure the load balancer settings (name, scheme, and listeners) according to your needs. Usually, you'll set up an HTTP or HTTPS listener.
Configure the availability zones and subnets where your instances will run.
Configure security groups to allow access to your application.
Configure a target group for your instances. The target group will be used by the load balancer to route traffic to the instances.
Review your settings and click "Create" to set up the load balancer.
Step 3: Create an Auto Scaling Group (ASG)
In the AWS Management Console, navigate to the EC2 Dashboard and click on "Auto Scaling Groups" in the left sidebar.
Click "Create an Auto Scaling group".
Select "Launch Configuration" and click "Create launch configuration".
Choose the previously created AMI as the base for your launch configuration.
Select the instance type that best fits your application requirements.
Configure the details of your launch configuration, such as name, IAM role, and monitoring settings.
Configure the storage and security group settings for the instances.
Review your settings and click "Create launch configuration". You'll be prompted to select or create a key pair.
Now, configure your Auto Scaling Group settings: group name, group size, and the VPC/subnets where your instances will run.
Choose the previously created target group for the load balancer.
Configure scaling policies based on CloudWatch alarms, such as average CPU utilization, request count, or other custom metrics.
Configure instance termination policies, notifications, and monitoring settings.
Review your settings and click "Create Auto Scaling group".
Step 4: Update your DNS records
In the AWS Management Console, navigate to the EC2 Dashboard and click on "Load Balancers" in the left sidebar.
Locate your newly created load balancer and copy its DNS name.
Update your domain's DNS records (A or CNAME) to point to the load balancer's DNS name.
After completing these steps, your Laravel application should be set up to auto-scale based on the scaling policies you defined. Make sure to monitor your application and adjust the scaling policies as needed.
@Brotzka When deploying new code to a "main" server in an auto-scaling environment, you don't necessarily have to rebuild the AMI or reconfigure the ELB every time. However, you need to ensure that new instances launched by the Auto Scaling Group (ASG) have the latest code and configuration.
@azimidev and how I "ensure that new instances launched by the Auto Scaling Group (ASG) have the latest code and configuration" through Laravel Forge? did you resolve it?