From its inception, AWS Elastic Beanstalk was designed to reduce the complexity of running web applications in the cloud. Elastic Beanstalk is also designed from the ground up to support multiple programming languages, including Node.js and Python.
As a platform, Elastic Beanstalk eliminates most of the hard work in setting up the right infrastructure for your web apps. You don’t have to manually provide resources or deal with infrastructure maintenance. This allows developers to focus on creating, deploying, and maintaining their apps instead.
One of the instances in which AWS Elastic Beanstalk becomes incredibly handy is in deploying apps that rely on data processing and analysis, specifically analysis that utilizes multiple models or algorithms. In this article, we are going to focus on the use of Elastic Beanstalk for time warping.
Time warping allows the processing of data across multiple time series; a common approach used in deeper analysis. Applications of time warping include examining deterministic build processes, debugging any time-related issues in your infrastructure—such as expired SSL certificates, or testing software for future diagnostics—such as year-2038 compliance for example.
The most common form of time warping is dynamic time warping (DTW), which compares and analyzes multiple time series.
DTW enables optimized algorithms to conform to certain warping functions. The process starts with the division of two series of data into equal points, which are then converted into a time warp; the process basically uses the Euclidean distance between points in the series to find similarities.
The previous process is repeated for every data point in the time series until all of them are analyzed. Warping has its restrictions to allow for more accurate calculation, with boundary conditions and slope constraint being the most common restrictions of them all.
Time Warping in Real Life
The implementation of time warping is endless, but the most common implementation can be seen in weather and temperature analysis. When comparing temperatures in two areas or more, scientists regularly utilize time warping to synchronize data points.
Time warping is also used in more advanced fields, including in the development of artificial intelligence and augmented reality applications. In the case of AI, time warping is used to interpolate signal values from two datasets in order to increase accuracy.
Assuming that there are two data streams, the analysis is conducted using warping function φ in order to generate ˜x = x ◦ φ ≈ y. As this form of analysis—as well as generalized time warping and canonical time warping—gets used more frequently, frameworks and modules are released to simplify the process.
A good example of time warping being deployed as a platform can be seen in the implementation of MetProt, a Node.js-based time warping tool that supports datasets in .csv and. rdata formats. Since MetProt is based on Node.js, it runs smoothly on AWS Elastic Beanstalk and is always ready for immediate use.
Time Warping in the Cloud
Sticking with MetProt as an example, you get a platform that can be used to analyze external data in the right format. As the name suggests, MetProt is a platform that analyzes and annotates Metabolomics datasets with Proteomics information. Chemical processes are analyzed from the datasets without time series being a serious obstacle.
Similar solutions—or even custom-built ones—can be deployed in an instant on Elastic Beanstalk. Since AWS Elastic Beanstalk can also be configured for certain computational needs, you can refine how the infrastructure is set up down to the kind of EC2 set up supporting the environment just as easily. Another example implementation is the GitHub tool libfaketime, a tool that easily modifies the system time for applications. Running libfaketime on your Amazon applications consists of two steps:
1. Making sure libfaketime gets loaded by the system’s linker.
2. Specify the faked time.
The tool works by intercepting various system calls that apps leverage to retrieve the current date and time. It then feeds back modified (warped) dates and times configured by the user. This means you can modify the system time a program sees without having to change the time system-wide.
At Ibexlabs, we have been using this libfaketime library for our Java application hosted in AWS Elastic Beanstalk. Our application does calculations on different dates in the future for our data analysis in this manner. Here’s an example of the time warping process in action:
Libfaketime and AWS Elastic Beanstalk
- First, we have to clone the repository from Github here and compile it using ‘make’, which will create our Beanstalk required files in the src/ directory.
- Create one folder in beanstalk extensions, e.g., ‘libfaketime’, and copy files ‘libfaketime.so.1’ and ‘libfaketimeMT.so.1’ taken from the src/ directory to the ‘libfaketime’ extensions folder.
- We have been using the following variables set on Beanstalk environment properties to change the time for the application.
DONT_FAKE_MONOTONIC=1 FAKETIME=@YYYY-MM-DD HH:mm:ss FAKETIME_NO_CACHE=1 LD_PRELOAD=/var/app/current/faketimefiles/libfaketime.so.1
One important thing to note is that we should also create one IAM user with AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and add those to the Beanstalk environment properties because an instance attached without IAM role permissions won’t work on future dates as expected.
- Next, create a custom script to update the Beanstalk environment properties to add required variables using the AWS CLI to change multiple dates automatically. We have been using Jenkins to run through different dates with given parameters over certain intervals.
- The following is the example AWS CLI command to update the environment properties on Beanstalk:
aws elasticbeanstalk update-environment –environment-name $BACKEND_ENVIRONMENT –option-settings Namespace=aws:elasticbeanstalk:application:environment,OptionName=FAKETIME,Value=”$FAKE_TIME” Namespace=aws:elasticbeanstalk:application:environment,OptionName=LD_PRELOAD,Value=/var/app/current/faketimefiles/libfaketime.so.1 Namespace=aws:elasticbeanstalk:application:environment,OptionName=FAKETIME_NO_CACHE,Value=1 Namespace=aws:elasticbeanstalk:application:environment,OptionName=DONT_FAKE_MONOTONIC,Value=1 Namespace=aws:elasticbeanstalk:application:environment,OptionName=AWS_ACCESS_KEY_ID,Value=”$AWS_ACCESS_KEY_ID” Namespace=aws:elasticbeanstalk:application:environment,OptionName=AWS_SECRET_ACCESS_KEY,Value=”$AWS_SECRET_ACCESS_KEY” –output json
- To change the date back to the original, you can just remove the additional Beanstalk environment properties added. The following is the example AWS CLI command to remove environment properties on Beanstalk:
aws elasticbeanstalk update-environment –environment-name $BACKEND_ENVIRONMENT –options-to-remove Namespace=aws:elasticbeanstalk:application:environment,OptionName=FAKETIME Namespace=aws:elasticbeanstalk:application:environment,OptionName=LD_PRELOAD Namespace=aws:elasticbeanstalk:application:environment,OptionName=FAKETIME_NO_CACHE Namespace=aws:elasticbeanstalk:application:environment,OptionName=DONT_FAKE_MONOTONIC Namespace=aws:elasticbeanstalk:application:environment,OptionName=AWS_ACCESS_KEY_ID Namespace=aws:elasticbeanstalk:application:environment,OptionName=AWS_SECRET_ACCESS_KEY –output json
- There are other different, optional variables to use as provided in the libfaketime repository.
Finally, with time warping there is no need to be concerned about scaling as that’s also not an issue. As your computational need grows, Elastic Beanstalk can make the necessary adjustments and maintain cloud environment health. A quick look at the Enhanced Health Overview is all you need to maintain a healthy cloud environment.
One thing for sure, Elastic Beanstalk makes time warping more accessible. Researchers, developers, and data scientists can fully take advantage of AWS cloud environment for data processing and analysis without having to be a master of server and cloud management.
Ibexlabs is an experienced DevOps & Managed Services provider and an AWS consulting partner. Our AWS Certified DevOps consultancy team evaluates your infrastructure and make recommendations based on your individual business or personal requirements. Contact us today and set up a free consultation to discuss a custom-built solution tailored just for you.