1001010110101010
Thank you! Our team will contact you soon

AMI FACTORY

  • Industry : Retail
  • Country : UAE
aws
serverless
next-generation
cdk
security

Cuple is one of the well-reputed retailers in Dubai specialized in footwear, bags, and perfumes for all age groups and genders - distributed across 15 branches in all UAE. Cuple offers a wide variety of collections in an up-to-date fashion provided that they are a Spanish brand that is always aiming after the latest European Trends. And recently, due to Covid-19 lock-down measures, Cuple initiated an e-commerce store to be able to sell their products online.

The Challenge

The evolving situation caused by Covid-19 led Cuple to rapidly establish its online shop over AWS Cloud Services accompanied by a marketing campaign to inform their clients about this continuity plan. As their e-commerce kicked, the website received around 5,000 requests in a short time frame, and consequently their website went down which unfortunately had their infrastructure down because it couldn’t handle the enormous traffic request growth without a highly elastic and available cloud hosting environment. Cuple realized the situation and decided to get consultancy from lead AWS Partners in the region to accommodate higher traffic volumes and upscale their infrastructure capacity seamlessly. Zero&One team had to re-factor and re-architect Cuple’s infrastructure by utilizing various AWS tools and technologies such as Application Load Balancer, Auto-Scaling, S3, RDS, EFS and CloudFront to achieve a fully-functional design over a weekend resulting in a successful campaign that can sustain millions of requests during peak time.

Our team had to use AWS EFS; a cloud storage service provided by AWS designed to provide scalable, elastic, and encrypted network file storage to store WordPress static folders such as wp-content and then mount it across all servers behind the Autoscaling group. AWS EFS was not the perfect solution for Cuple due to the burst credit limits that was easily throttled by the PHP application as a result of high IOPS utilization. To overcome the high IOPS utilization, we had to either use the EFS provisioned throughput mode or set up a RAID 10 array that can improve disk performance and data consistency by utilizing the stripping and mirroring features of RAID 0 and RAID 1. However, both solutions will incur more charges on our client’s monthly bill. So, we had to migrate the wp-content folder from EFS back to the root EBS volumes and only mount the uploads folder to EFS. Even though this approach had the application get back on track, creating manual AMIs and new launch configurations was obligatory after each WordPress update that cannot be saved in the database. Typically, updating an autoscaling group with a new launch configuration had to be executed manually and then older instances are gradually replaced with newer ones across multiple availability zones. Several days later and knowing the fact that Cuple team constantly runs marketing campaigns along with several CMS plugins updates, this manual process was identified as a risk that is first and foremost time consuming and could result in an unexpected application failure if configured improperly.

The Benefits

Given the fact that all these activities had to be executed in line with the marketing campaigns, Zero&One team was able to achieve a fully-functional design over a weekend resulting in a successful campaign that can sustain millions of requests during peak time. Moreover, at a later phase, Zero&One team kept monitoring activity, reiterated, and optimized the design to lodge more IOPs as Cuple had an even bigger campaign (10 times the first) reflecting the flexibility and scalability of AWS Solutions.

Knowing the huge traffic Cuple website was experiencing, Zero&One engineers had to utilize Auto Scaling that is a cost-effective solution by AWS that provides a fault-tolerant and scalable infrastructure while keeping the operating costs as low as possible. Load balancing is crucial to achieving the benefits of auto-scaling and this is where our team decided to use the Application Load Balancer (ALB) for the WordPress CMS with content routing to distribute the traffic evenly between EC2 instances. CloudFront was then configured to cache static and dynamic content that in return delivers it to end-users immediately if available in the nearest edge location. Setting up CloudFront for WordPress required one distribution, two origins, and several behaviors targeting various WordPress files and folders such as wp-content, wp-admin, and wp-login.php file where each of these contents has a unique HTTP and caching methods

Moreover, AWS RDS for MySQL with multi A-Z were hosted for the WordPress database that is a fully managed MySQL database that adds more scalability and high availability to the environment by replicating the RDS instances between multiple availability zones. AWS S3 also improved the server’s utilization by storing thousands of images in a restricted bucket that is only accessible by CloudFront using origin access identity.

Solution

Zero&One DevOps team had to come with a solution that can reduce the manual overhead by automating the whole process using AWS Lambda, API Gateway, and some API calls that AWS provides to end users out of the box. Now how does all this work? Simply, invoke the Lambda Function either through AWS CLI, API gateway with authorization, or even from Slack using AWS Chatbot and let the magic happen in a couple of seconds. AWS Lambda offers a simple and straightforward serverless platform that supports several languages such as Python, Java, Node.js, C#, and more. For this tutorial, we will be using Node.js to create our function.

Users will first provide IAM credentials to an API Gateway via a post method to make sure that only authorized personnel can invoke the lambda function. Once the user is authorized and temporary credentials are generated, API Gateway will invoke the Lambda Function that will in return starts creating a new AMI for the running instance, changes the launch configuration settings, and then updates the Autoscaling Group with the latest AMI.

cuple aws case study solution

Let’s now have a look at the TypeScript code.
First things first we have to import all necessary modules that our lambda use and define the required user input during a POST or AWS CLI request. cuple aws case study solution Then we declare an event trigger handler with some identifiers and variables that first get the current date, then parse the user input that should include the current autoscaling group name and instance ID from which the new AMI image is created by the ciResponse variable.

In the next step, we describe the current autoscaling group and launch configuration, and get all the required parameters that we will use afterwards to create a new launch configuration attached to the most recent AMI ID. Now here comes the tricky part of this automated process. An EBS snapshot is a backup of the instance EBS volume that stores all your data. Once an AMI image is created, the EBS snapshot of a specific instance is associated with it by default. Unfortunately, creating a new launch configuration using code will result in an AMI image with no disks attached to it and will fail to boot the instance accordingly. A workaround for this hassle is to manually define the EBS block device mappings and associate it with the newly created launch configuration. Finally, we just update the current autoscaling group with the new launch configuration. Our team made it simple to setup the automated AMI Factory by utilizing AWS CDK. I will try as much as possible to simplify the deployment of AMI Factory by following the below steps.
  1. Make sure you have Node.js and the AWS CDK Toolkit installed
  2. Clone the project that we have made public for you.
  3. Install the typescript compiler on your local machine, and all npm dependencies to the local node_modules folder.
  4. Compile TypeScript to JS by running the “npm run build” command. This will create the JavaScript file “asg-configuration.js” that AWS Lambda will use as a handler.
  5. Run “cdk deploy” and voila! CDK will take care of setting up the entire AWS infrastructure for you.
  6. Create a new launch configuration using Postman.
A few things to notice:
  • Our function uses Node.js 12.x runtime
  • The handler code is loaded from the “npm run build” command which compiles typescript to js
  • The name of the handler function is asg-configuration.handler

Conclusion

Cuple team is currently expanding their cloud adoption on AWS through many regions with the help of our tailor-made automated AMI Factory that eliminated unexpected human errors and operational overhead. Cuple is currently running multiple weekly campaigns and performing several updates on its backend and frontend environments without affecting the digital e-commerce experience of its end-users. AMI Factory is with no doubt a rescuer for workloads that require consecutive changes on their running EC2 instances while utilizing a highly available and resilient cloud infrastructure on AWS without disruption.

About Zero&One

Zero&One is a leading Premier AWS Consulting Partners in MENA region with a vision to empower businesses of all scales in their cloud adoption journey. We specialize in AWS services like DevOps, application modernization, cloud migration and serverless computing. We currently operate from our offices in Lebanon, UAE, and Saudi with 100+ certifications in our hands and serve 50+ happy customers across the region.

01
Contact Us

We'd like to hear from you

Protect yourself and others from the covid-19 pandemic. Learn more