Secure API Access via AWS Elastic IP and Proxy

Accessing Isolated Networks via AWS Elastic IP and Proxy

Accessing Isolated Networks via AWS Elastic IP and Proxy

When working with enterprise APIs or isolated client networks, it’s common to be asked to access their environment from a known static IP. If your development environment is dynamic or cloud-based, AWS provides an elegant solution using Elastic IPs and proxy servers.


๐ŸŽฏ Problem: Static IP Required for API or Network Access

Many enterprise systems and secure networks restrict access to a fixed set of whitelisted IP addresses. If you’re working from a laptop, development environment, or cloud VPC without a static public IP, your requests may be blocked or rejected for security reasons.

โœ… Common Scenarios:

  • API firewalls requiring static IP
  • Private VPC-to-VPC access between organizations
  • Testing from different geographic regions via a whitelisted IP

๐Ÿงฉ Solution 1: Static IP from ISP or VPN

If your internet provider offers a static IP, you can request access using that. However:

  • โœ… Simple and local
  • โŒ Not portable โ€” tied to location or hardware
  • โŒ Changing locations breaks access

๐ŸŒฉ๏ธ Solution 2: Use AWS Elastic IP + Proxy

AWS Elastic IP is a fixed, public IPv4 address you can attach to EC2. By setting up a proxy server on the EC2 instance, you can route any request (from browser, backend, or script) through this IP.

โœ… Advantages:

  • ๐ŸŽฏ Globally accessible
  • ๐Ÿ” Easily secured via AWS Security Groups
  • ๐Ÿ› ๏ธ Fully scriptable and scalable

๐Ÿ”ง Step-by-Step: Setup HTTP Proxy with Squid on EC2

  1. Launch EC2:
    • Use Ubuntu 20.04 or 22.04
    • Instance type: t2.micro (Free Tier eligible)
    • Allow SSH (port 22) and custom TCP port (3128)
  2. Allocate and associate an Elastic IP:
    • In the AWS EC2 dashboard โ†’ Elastic IPs โ†’ Allocate
    • Associate this IP with your running EC2 instance
  3. Install Squid:
    sudo apt update && sudo apt install squid -y
  4. Configure Proxy Access:
    Edit the configuration file:
    sudo nano /etc/squid/squid.conf
    Add or modify these lines:
    http_port 3128
      
      # Allow all (or restrict to your IP)
      acl allowed_ips src 0.0.0.0/0
      http_access allow allowed_ips
      http_access deny all

    Note: Replace 0.0.0.0/0 with your IP range for added security (e.g., 203.0.113.0/24 or YOUR_IP/32).

  5. Restart the Squid service:
    sudo systemctl restart squid

    Optional: check status

    sudo systemctl status squid
  6. Open port 3128 in your EC2 Security Group:
    • Go to EC2 โ†’ Security Groups โ†’ Inbound rules โ†’ Add Rule
    • Type: Custom TCP
    • Port: 3128
    • Source: Your IP or 0.0.0.0/0 (if testing)
  7. โœ… Share the Elastic IP with Your Client

    Provide the client with your Elastic IP address to allow in their firewall or API gateway. For example:

    Static IP: 54.123.45.67

๐Ÿ” How to Restrict Proxy Access

  • ๐Ÿ›ก๏ธ Use Squidโ€™s acl allowed_ips to allow only specific IPs
  • ๐Ÿ”’ Secure EC2’s Security Group to your developer IPs only

๐ŸŒ How to Use the Proxy (Elastic IP) with Real API Calls

Once your proxy is live (e.g., http://54.123.45.67:3128), hereโ€™s how to route your traffic through it from different environments.

๐Ÿงช 1. curl

curl -x http://54.123.45.67:3128 https://jsonplaceholder.typicode.com/posts/1

๐ŸŒ 2. Google Chrome (System Proxy)

๐Ÿ“ฌ 3. Postman

  • Go to Settings โ†’ Proxy
  • Set:
    • Proxy Type: HTTP
    • Server: 54.123.45.67
    • Port: 3128
  • Enable global proxy or per-request proxy
  • Make a GET request to https://jsonplaceholder.typicode.com/posts/1

๐Ÿ’Ž 4. Ruby on Rails (Faraday Example)

conn = Faraday.new(
    url: 'https://jsonplaceholder.typicode.com',
    proxy: 'http://54.123.45.67:3128'
  )
  
  response = conn.get('/posts/1')
  puts response.body
  

๐Ÿ•น๏ธ 5. WebGL / Browser Fetch (via system proxy)

Browser apps (including WebGL) will automatically use system-level proxy settings.

Follow the Chrome system proxy setup above, then run:

fetch('https://jsonplaceholder.typicode.com/posts/1')
    .then(res => res.json())
    .then(console.log)

๐Ÿง  6. Node.js (with axios + https-proxy-agent)

const axios = require('axios');
  const HttpsProxyAgent = require('https-proxy-agent');
  
  const proxyAgent = new HttpsProxyAgent('http://54.123.45.67:3128');
  
  axios.get('https://jsonplaceholder.typicode.com/posts/1', {
    httpsAgent: proxyAgent
  }).then(res => console.log(res.data))
    .catch(err => console.error(err));
  

โš›๏ธ 7. React (via Node backend or dev proxy)

React apps can’t directly configure HTTP proxies in browser JS. You should:

  • Use a proxy-aware backend (e.g., Node, Rails)
  • Or run a local proxy via http-proxy-middleware during development

React Dev Proxy (Optional) โ€” in package.json:

{
    "proxy": "http://54.123.45.67:3128"
  }

โš ๏ธ This only works for same-origin development APIs. Better to use a backend like Node or Rails to proxy requests through EC2.


โ“ Why Use a Proxy?

A proxy server acts as an intermediary between your app and the target API. When routed through EC2, it makes requests appear to come from the Elastic IP.

โœ… Use Cases:

  • Bypass network restrictions (ethically)
  • Route all outbound API requests from a known IP
  • Debug and log requests from multiple sources

โš ๏ธ Proxy Risks:

  • Open proxies may be abused if not secured
  • Must monitor usage to prevent misuse

๐Ÿ”„ Alternatives to Proxy Access

MethodProsCons
VPN TunnelSecure, bidirectionalComplex setup, requires client VPN support
VPC PeeringLow latency, internal IPsOnly for AWS-to-AWS, hard to manage across orgs
PrivateLink / Transit GatewayHighly secure AWS-to-AWS accessCostly, complex to set up
Elastic IP + Proxy (Recommended)Easy, works globally, scalableRequires proxy config and IP restrictions

๐Ÿ“Œ Conclusion

If your client requires access from a fixed IP address, using an AWS EC2 + Elastic IP + HTTP Proxy is a clean, scalable, and secure solution โ€” especially when combined with IP allowlisting and AWS security groups.

Learn more aboutย Cloud

Scroll to Top