skip to Main Content

So we are launching an ecommerce store built on magento. We are looking to deploy it on Amazon EC2 instance using RDS as database service and using amazon auto-scaling and elastic load balancer to scale the application when needed.

What I don’t understand is this:
I have installed and configured my production magento enviorment on an EC2 instance (database is in RDS). This much is working fine. But now when I want to dynamically scale the number of instances

  • how will I deploy the code on the dynamically generated instances each time?
  • Will aws copy the whole instance assign it a new ip and spawn it as a
    new instance or will I have to write some code to automate this
    process?
  • Plus will it not be an overhead to pull code from git and deploy every time a new instance is spawned?

A detailed explanation or direction towards some resources on the topic will be greatly appreciated.

2

Answers


  1. You do this in the AutoScalingGroup Launch Configuration. There is a UserData section in the LaunchConfiguration in CloudFormation where you would write a script that is ran when ever the ASG scales up and deploys a new instance.

    https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-launchconfig.html#cfn-as-launchconfig-userdata

    This is the same as the UserData section in an EC2 Instance. You can use LifeCycle hooks that will tell the ASG not to put the EC2 instance into load until everything you want to have configured it set up.

    https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-as-lifecyclehook.html

    I linked all CloudFormation pages, but you may be using some other CI/CD tool for deploying your infrastructure, but hopefully that gets you started.

    Login or Signup to reply.
  2. To start, do check AWS CloudFormation. You will be creating templates to design how the infrastructure of your application works ~ infrastructure as code. With these templates in place, you can rollout an update to your infrastructure by pushing changes to your templates and/or to your application code.

    In my current project, we have a github repository dedicated for these infrastructure templates and a separate repository for our application code. Create a pipeline for creating AWS resources that would rollout an updated to AWS every time you push to the repository on a specific branch.

    • Create an infrastructure pipeline
    • have your first stage of the pipeline to trigger build whenever there’s code changes to your infrastructure templates. See AWS CodePipeline and also see AWS CodeBuild. These aren’t the only AWS resources you’ll be needing but those are probably the main ones, of course aside from this being done in cloudformation template as mentioned earlier.

    how will I deploy the code on the dynamically generated instances each time?

    • Check how containers work, it would be better and will greatly supplement on your learning on how launching new version of application work. To begin, see docker, but feel free to check any resources at your disposal
    • Continuation with my current project: We do have a separate pipeline dedicated for our application, but will also get triggered after our infrastructure pipeline update. Our application pipeline is designed to build a new version of our application via AWS Codebuild, this will create an image that will become a container ~ from the docker documentation.
    • we have two triggers or two sources that will trigger an update rollout to our application pipeline, one is when there’s changes to infrastructure pipeline and it successfully built and second when there’s code changes on our github repository connected via AWS CodeBuild.
    • Check AWS AutoScaling , this areas covers the dynamic launching of new instances, shutting down instances when needed, replacing unhealthy instances when needed. See also AWS CloudWatch, you can design criteria with it to trigger scaling down/up and/or in/out.

    Will aws copy the whole instance assign it a new ip and spawn it as a new instance or will I have to write some code to automate this process?

    • See AWS ElasticLoadBalancing and also check out more on AWS AutoScaling. On the automation process, if ever you’ll push through with CloudFormation, instance and/or containers(depending on your design) will be managed gracefully.

    Plus will it not be an overhead to pull code from git and deploy every time a new instance is spawned?

    • As mentioned, earlier having a pipeline for rolling out new versions of your application via CodeBuild, this will create an image with the new code changes and when everything is ready, it will be deployed ~ becomes a container. The old EC2 instance or the old container( depending on how you want your application be deployed) will be gracefully shut down after a new version of your application is up and running. This will give you zero downtime.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search