Create JMeter Golden Image using Packer on AWS

In the last post, we saw about deploying JMeter on AWS using HashiCorp Terraform. I have also posted a YouTube video about it. Terraform helps to create and manage the infrastructure quickly and efficiently. When you use the JMeter module, it basically installs Java, JMeter, and JMeter plugins on the fly on an EC2 instance. How about creating an image with JMeter and dependencies for multiple platforms? Enter HashiCorp Packer. In this blog post, we will see how to Create JMeter Golden Image using Packer on AWS.

What is a Packer?

Packer is an open source tool from HashiCorp that enables you to create identical machine images for multiple platforms from a single source template.

Packer helps to collaborate between multiple teams to create, manage, and consume golden images.

What is a Golden Image?

The Golden Image is nothing but a template. It is a template for a Virtual Machine, server, desktop, or container. The other names of golden image are master image, clone image etc.

The Golden Image will have all the necessary software libraries, configuration settings and other dependencies to get started.

Prerequisites

The following are the prerequisites to create a golden image for JMeter on AWS using Packer:

  • Packer
  • AWS Console access w/ relevant privileges

Getting Started

Packer

Head to packer.io to install Packer based on your operating system. In this demo, I am going to use WSL for Linux.

curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -

sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"

sudo apt-get update && sudo apt-get install packer

To install auto-complete, enter packer -autocomplete-install.

To verify the installation, enter packer version

AWS CLI Configure

Install the AWS CLI and configure the access ID, secret key, default region, and output.

Packer JMeter Repo

Clone the Packer JMeter repo into your folder.

git clone https://github.com/QAInsights/Packer-JMeter.git

cd into Packer-JMeter\file or Packer-JMeter\shell

Before building the packer, make sure all the configurations are properly entered in jmeter-amazon.pkr.hcl

If you would like to customize the region, JMeter version, JMeter plugins and more, you can make changes at jmeter-amazon.pkr.hcl.

Building the Image

Before building the image, it is recommended to inspect the packer file. Enter packer inspect jmeter-amazon.pkr.hcl

The following would be the output.

Packer Inspect: HCL2 mode

> input-variables:

var.jmeter_cmdrunner_version: "2.2"      
var.jmeter_plugins_manager_version: "1.7"
var.jmeter_version: "5.4.3"

> local-variables:


> builds:

  > <unnamed build 0>:

    sources:

      amazon-ebs.jmeter

    provisioners:

      shell

    post-processors:

      <no post-processor>

To format, enter packer fmt .

To validate, enter packer validate .

Finally, to build the image, enter packer build .

Packer will validate all the configurations, create a temporary key pair, temporary security group, temporarily spins up a t2.small EC2 instance to create the image.

During the image creation process, Packer will download and install Java, JMeter, and JMeter Plugins on the EC2 instance.

Typically, it will take 3-5 minutes to create the image.

If any error occurs, it will be displayed on the terminal.

The output of this process will be AMI ID and the region.

Here is the partial output.

amazon-ebs.jmeter: output will be in this color.

==> amazon-ebs.jmeter: Prevalidating any provided VPC information
==> amazon-ebs.jmeter: Prevalidating AMI Name: jmeter_1643499054
    amazon-ebs.jmeter: Found Image ID: ami-001089eb624938d9f
...
...
...
...
==> amazon-ebs.jmeter: No volumes to clean up, skipping
==> amazon-ebs.jmeter: Deleting temporary security group...
==> amazon-ebs.jmeter: Deleting temporary keypair...
Build 'amazon-ebs.jmeter' finished after 3 minutes 59 seconds.

==> Wait completed after 3 minutes 59 seconds

==> Builds finished. The artifacts of successful builds are:
--> amazon-ebs.jmeter: AMIs were created:
us-east-2: ami-095b20c4727d864cb

Congratulations. You have created a golden image for JMeter.

Spin up an EC2 instance on AWS

The next step is to create an EC2 instance on AWS using this golden image. Head to AWS console and select the right region. In this case, it would be Ohio.

Navigate to EC2 > AMIs section. Select the AMI, click on Launch instance from Image.

Launch Instance from Image
Launch Instance from Image

Follow the wizard to configure the instance family, storage, security group, tags and more. Finally, click on Review and Launch.

Validate the AMI

After the successful launch of EC2 instance, ssh into it to validate the JMeter.

Copy the public IP of the EC2 instance to SSH into the instance.

$ ssh -i <key.pem> ec2-user@<public-ip>

To validate the JMeter folder, enter ls.

To validate the JMeter plugins’ status, enter the following commands from the home directory.

$ sudo chmod +x apache-jmeter-5.4.3/bin/PluginsManagerCMD.sh

$ sudo apache-jmeter-5.4.3/bin/PluginsManagerCMD.sh status

The output will display the installed JMeter plugins.

Deregister and Delete

Once the validation is done, do not forget to terminate the instance.

To deregister the AMI, go to EC2 > AMIs, select the AMI to deregister, then go to Actions > Deregister AMI.

Deregister AMI
Deregister AMI

These AMIs are created using EBS backed volume.

Amazon EBS-backed AMI – The root device for an instance launched from the AMI is an Amazon Elastic Block Store (Amazon EBS) volume created from an Amazon EBS snapshot.

For EBS-backed AMI, there are charges on instance usage, EBS volume usage, storing the AMI as an EBS snapshot.

In the Packer file, you can see the name of the AMI is amzn2-ami-kernel-5.10-hvm-*-x86_64-gp2. The cost of gp2 at this time of writing is $0.10 per GB-month of provisioned storage.

It is critical to delete the unwanted EBS snapshots from EC2 > Snapshots under Elastic Block Store section.

Select the snapshot, go to Actions > Delete snapshot.

Delete EBS snapshot
Delete EBS snapshot

Conclusion

Creating a golden image using Packer helps to collaborate with multiple teams, manage the image for a quick and easy deployment for performance testing. Packer helps to create images across multiple platforms, gels with the CI/CD pipeline, and is easy to learn and implement.

About the Author

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Hamster - Launch JMeter Recent Test Plans SwiftlyDownload for free
+
Share via
Copy link