Setting Up a Remote Wiremock Instance on AWS: A Comprehensive Guide

This blog post will guide you through setting up a remote Wiremock instance on an Amazon Web Services (AWS) EC2 Windows machine. Wiremock is a powerful tool for mocking external HTTP services in your tests, and using a remote instance allows you to manage your mocks from a central location.

Prerequisites:
  • An AWS account (you can sign up for a free tier account)
  • Basic understanding of networking concepts like firewalls and ports

Steps:

  1. Create an AWS Free Tier Account:

    • Visit the AWS website and search for "free tier account."
    • Follow the steps to sign up for an account, including providing your email address, password, and credit card information (AWS will not charge you if you stay within the free tier limits).
  2. Create a Windows EC2 Instance:

    • Sign in to the AWS Management Console using your AWS account credentials.
    • Search for "EC2" and select "EC2."



    • Click on "Launch Instance."

    • Choose a name for your instance (e.g., "wiremock-instance").

    • Select a free tier eligible Windows Server instance.


    • Under "Network Settings," keep the default settings.
    • Under "Security Groups," select the existing rule that allows HTTP traffic from anywhere (this will be temporarily adjusted later for security).


    • Choose a free tier eligible storage option.


    • Review your selections and click "Launch Instances."
    • AWS will create your instance and assign it a public IP address. Take note of this IP address, as you will need it to connect later.

3. Connect to the EC2 Instance from Localhost:

  • AWS offers two firewalls that need to be configured to allow access to your instance: the security group firewall and the Windows firewall.
  • Security Group Firewall:
    • Go to the EC2 Management Console and select "Security Groups."


      • Edit the inbound rules for the security group associated with your instance. By default RDP should be there, if not configure it as below


      • Connect to your EC2 instance using Remote Desktop Protocol (RDP) with the downloaded key pair file and the provided password.

  • Now connect using windows RDP or any other RDP tool.
  • Once connected, configure wiremock like we do on local by following below steps

4. Set Up Wiremock Server on the Remote EC2 Instance:

  • Install Java: You'll need Java installed to run the Wiremock standalone JAR file. Download and install the latest version of Java from the official Java website.

  • Download Wiremock Standalone JAR: Download the Wiremock standalone JAR file from the Wiremock website.

  • Start the Wiremock Server: Open a command prompt or PowerShell window on the remote instance and navigate to the directory where you downloaded the JAR file. Run the following command to start the Wiremock server:

    java -jar wiremock-standalone.jar
5. Access Remote Wiremock Instance from Local Machine:
    • Now you are all set to access remote instance from anywhere, here we will discuss how you can access it from your local machine
    • Whitelist the port(8080) where wiremock is deployed, in AWS virtual firewall 


    • Add inbound rule with TCP port 8080 and source is the IP of the machine from where you will be accessing wiremock instance, here 0.0.0.0 means it can be accessed from anywhere.
    • Now we have to enable inbound traffic for 8080 port via windows firewall 
    • Open advance firewall setting on EC2 machine


    • Now navigate to inbound rules on left bar 



    • Add new rule from options bar on the right. Select Port 

  • Click next and select TCP. Specify port 8080
 
    • Select all the options to apply the rule


    • You should now be able to access the Wiremock admin interface on your local machine by opening a web browser and navigating to http://<your_instance_public_IP>:8080/__admin.


    • If you encounter any issues, double-check your firewall configurations on both the AWS security group and the Windows firewall.

Important Note:

The steps above allow access to your instance from anywhere with an internet connection. For production environments, it's crucial to restrict access using a more secure approach like security groups with specific IP ranges or IAM roles.

By following these steps, you'll have a remote Wiremock instance set up on AWS, allowing you to manage your mocks centrally and enhance your application testing efficiency.

Comments

Popular posts from this blog

API MOCKING/SERVICE VIRTUALIZATION: HOW DOES IT WORK?

Test Doubles 101: Mocks, Stubs, Fakes, and Virtual Services Explained