Deploying on AWS EC2
This guide will help you deploy your Botasaurus Desktop API on an AWS EC2 instance. The process is straightforward and involves creating an Elastic IP, setting up an EC2 instance, and installing your desktop application.
Step-by-Step Deployment Guide​
1. Reserve a Static IP Address​
First, we'll reserve an Elastic IP address. An Elastic IP ensures your EC2 instance is always reachable at the same IP address.
-
Create an AWS Account if you don't already have one.
-
Go to the Elastic IP addresses page.
-
Click the "Allocate Elastic IP address" button.
-
Keep the default settings and click "Allocate"
This creates an Elastic IP address that you'll use to access your app. You will assign this IP to your EC2 instance in the next step.
2. Create an AWS EC2 Instance​
-
Go to the EC2 Dashboard and click "Launch Instance"
-
Configure your instance with these recommended settings. You may change the Machine Type and Boot Disk Size based on your scraping needs:
Section | Setting | Value | Notes |
---|---|---|---|
Name and tags | Name | yahoo-finance | Use your app name as the instance name |
Application and OS Images (AMI) | Amazon Machine Image (AMI) | Ubuntu Server 24.04 LTS | A .deb installer requires a Debian-based OS like Ubuntu. |
Instance type | Instance type | t3.medium | 2 vCPU, 4 GB memory. Change based on needs |
Key pair (login) | Key pair name | Create new key pair > RSA (.pem) | Required for SSH access |
Network settings | Allow SSH traffic from | ✓ | Required for terminal access |
Network settings | Allow HTTP traffic from the internet | ✓ | Required for accessing API via HTTP |
Network settings | Allow HTTPS traffic from the internet | ✓ | Required for accessing API via HTTPS |
Configure storage | Storage | 20 GiB - Magnetic | Magnetic is the cheapest disk type. |
- Optionally, if you're scraping data for your own needs, enable Spot Instances as they are 70-90% cheaper than On-Demand instances. Enable them with these settings:
Section | Setting | Value | Notes |
---|---|---|---|
Advanced details | Purchasing option | Spot Instances | Enables Spot Instances |
Customize Spot instance options | Request type | Persistent | - |
Customize Spot instance options | Interruption behavior | Stop | - |
Don't use Spot VMs for customer-facing APIs or mission-critical applications, as they can be stopped by AWS at any time if the resources are needed elsewhere.
-
Click Launch instance.
-
Now, associate the Elastic IP:
- Go to Elastic IPs
- Select your previously created Elastic IP
- Click Actions > Associate Elastic IP address
- Select your newly created instance and click Associate
-
Connect to your instance via SSH:
- Go to EC2 Instances
- Select your instance
- Click Connect > EC2 Instance Connect
- Click the Connect button
3. Installing Your Desktop App​
Now that your EC2 instance is ready, let's install your Botasaurus Desktop API.
-
First, install the necessary packages on your instance by running the command below. This script installs Botasaurus CLI and the Apache web server to manage requests to your app.
curl -sL https://raw.githubusercontent.com/omkarcloud/botasaurus/master/vm-scripts/install-bota-desktop.sh | bash
-
Upload your app to S3 following the packaging and publishing guide. A Debian installer will be saved in the S3 bucket, which we will use in the next step. It looks like this:
https://your-bucket.s3.amazonaws.com/Your-App-amd64.deb
-
Next, install the desktop application on the EC2 instance.
- If you have already uploaded your app to S3, replace the link in the command below with your own Debian installer URL.
- If you only want to test the installation, keep the sample URL as is.
python3 -m bota install-desktop-app --debian-installer-url https://yahoo-finance-extractor.s3.us-east-1.amazonaws.com/Yahoo+Finance+Extractor-amd64.deb
Configuration OptionsThe
install-desktop-app
command supports these options:--port
: Sets the port for the app (e.g.,8001
). An alternative toApiConfig.setApiPort
.--api-base-path
: Adds a prefix to all API routes (e.g.,/yahoo-finance
). An alternative toApiConfig.setApiBasePath
.--skip-apache-request-routing
: Disables automatic Apache configuration for the API. Use it if you want to manually configure other load balancers like Nginx.
When the installation completes, you'll see a link to your API documentation. Visit it see the api.
To host additional applications on the same instance, you must use the --port
and --api-base-path
flags to prevent conflicts:
--port
with different ports (e.g.,--port 8001
)--api-base-path
with unique paths (e.g.,--api-base-path /amazon-invoices
)
For example, run this command to add an Amazon Invoice extractor alongside the Yahoo Finance extractor:
python3 -m bota install-desktop-app \
--debian-installer-url https://amazon-invoice-extractor.s3.us-east-1.amazonaws.com/Amazon+Invoice+Extractor-amd64.deb \
--port 8001 \
--api-base-path /amazon-invoices
The Amazon Invoice API will now be available at: http://<your-elastic-ip>/amazon-invoices
.
How to Uninstall the Desktop App?​
Before uninstalling, download any important data. This action is irreversible and will result in permanent data loss.
To uninstall the application from the EC2 instance, use one of the following methods:
Method 1: Using Debian Installer URL
Replace https://yahoo-finance-extractor.s3.us-east-1.amazonaws.com/Yahoo+Finance+Extractor-amd64.deb
with your app's Debian installer URL:
python3 -m bota uninstall-desktop-app --debian-installer-url https://yahoo-finance-extractor.s3.us-east-1.amazonaws.com/Yahoo+Finance+Extractor-amd64.deb
Method 2: Using Package Name
-
Find your package name in
package.json
: -
Uninstall using the package name:
python3 -m bota uninstall-desktop-app --package-name yahoo-finance-extractor
How to Delete the EC2 Instance and Avoid Incurring Further Charges?​
Before deleting the instance, download any important data to avoid permanent loss.
To prevent ongoing costs, you must delete both the EC2 instance and release the Elastic IP address as follows:
-
Cancel the Spot Request (Spot VMs only) If you have enabled Spot Instances, cancel the Spot request before deleting the instance. Otherwise, they will keep respawning, again and again. To cancel the Spot request:
- Go to Spot Requests
- Select your Spot request
- Click Actions > Cancel request
- Click Confirm to cancel
-
Terminate the EC2 Instance
- Go to EC2 Instances
- Select your instance
- Click Instance state > Terminate (delete) instance
- Click Terminate (delete) to confirm
-
Release the Elastic IP Address
- Go to Elastic IPs
- Select your Elastic IP
- Click Actions > Release Elastic IP address
- Click Release to confirm
That's it! You have successfully deleted the EC2 instance and released the Elastic IP. You will not incur any further charges.