Skip to main content

AWS IoT Tunnel Script

Overview

The aws_iot_tunnel.py script sets up and manages a secure tunnel to an AWS IoT device using the AWS IoT Secure Tunneling feature by checking for existing open tunnels to avoid unnecessary opening of new tunnels. It leverages prebuilt Docker images from aws-iot-securetunneling-localproxy to create a secure connection, enabling interaction with IoT devices from your local environment. By opening a tunnel on your machine, you can easily use development tools like VSCode, which cannot be utilized via the AWS web UI.

Table of Contents

Requirements

Before running the script, ensure you have the following installed:

  • Python 3.x
  • AWS CLI (Configured)
  • Docker: Required to run the tunnel in a container.
  • boto3 (AWS SDK): To manage secure tunneling (automatically installed with pip).
  • docker (Docker SDK): To manage docker container (automatically installed with pip).

Installation

Download the script directly or clone this repository:

pip install aws-iot-tunnel

OR

git clone https://github.com/smartdings/aws-development-tools.git
pip install ./aws-development-tools/iot/tunnel

Usage

  1. Run the docker container.

    aws-iot-tunnel -t MyIoTThing -p myawsprofile -r us-west-2
    
  2. Connect to the iot thing using SSH.

    ssh user@localhost -p 5555
    

Command-Line Arguments

Argument Short Form Type Required Description
--thing-name -t string Yes Name of the AWS IoT Thing to connect to.
--port -P int No Port to bind (defaults to 5555).
--profile -p string No AWS profile to use for authentication.
--region -r string No AWS region to use (defaults to the configured region).
--remove-fingerprint -R No Remove SSH fingerprint on localhost with specified port.
--new-tunnel -N No Open a brand-new tunnel and leave any existing open tunnel(s) for the thing untouched (they are not closed).
--v2 -V No Use the V2 local-proxy protocol instead of the V1 default. V2 supports multiple simultaneous sessions per tunnel, but requires the destination device's local proxy to also support V2.

How It Works

  1. boto3 SDK: The script interacts with the AWS IoT Secure Tunneling service using boto3 SDK to manage tunnels and rotate access tokens.
  2. Docker Integration: It runs a Docker container configured for the appropriate architecture to establish a secure tunnel to the specified IoT device.
  3. Token Management: The script checks for existing tunnels and manages the source access tokens required for secure communication. AWS IoT Secure Tunneling allows multiple tunnels to stay open for the same thing at once. If more than one open tunnel is found (e.g. after using --new-tunnel), the script lists them and prompts you to pick one to reuse, defaulting to the most recently created tunnel.
  4. Explicit New Tunnels: Use --new-tunnel/-N to always open a fresh tunnel instead of reusing an existing one. The previous tunnel(s) are left open (not closed) — the IoT device automatically reconnects its local proxy to whichever tunnel was opened most recently, so older tunnels become inactive but still count toward your account's tunnel quota until they expire.
  5. Docker Container Naming and Conflicts: Each Docker container is named after the thing name and the tunnel ID it's proxying (e.g. MyIoTThing-<tunnel-id>) and labeled with both, so docker ps/docker inspect tell you exactly which AWS IoT tunnel each container belongs to. The port isn't part of the name — docker ps already shows each container's port mapping, and this script only ever runs one local-proxy container per tunnel. Two conflicts are checked before starting: (a) another container already bound to the requested host port (could be any thing/tunnel), and (b) this exact tunnel already having a running container on a different port. Either one prints who's holding it and asks whether to stop it, defaulting to no; declining leaves it running and the script exits without starting a new one. In a non-interactive session the prompt is skipped and defaults to "no" automatically. A stopped, not-yet-removed container from a previous run is cleaned up silently (no prompt) since it isn't actually in use. Multiple simultaneous tunnels to the same thing are still fully supported — each one gets a different tunnel ID (and can use a different port).
  6. Local-Proxy Protocol Version: The local proxy container runs with --destination-client-type V1 by default, matching what the destination device's local proxy is expected to speak. Pass --v2/-V to use the V2 protocol instead, which lets a single tunnel carry multiple simultaneous sessions (e.g. more than one SSH connection through the same tunnel/port at once) — but only if the destination device's local proxy also supports V2; otherwise the two sides fall back to mismatched framing and the tunnel silently drops connections instead of proxying data.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Key Features of the README

  • Overview: A brief introduction to what the script does.
  • Requirements: Specifies what is needed to run the script.
  • Installation: Instructions on how to set up the script.
  • Usage: Clear command examples for users to follow.
  • Command-Line Arguments: A table detailing each argument, its type, and whether it's required.
  • How It Works: A high-level explanation of the script's functionality.
  • License: Information about the licensing of the project.

Metadata

Release files for aws-iot-tunnel 0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-iot-tunnel 0.12
File Size Uploaded
aws_iot_tunnel-0.12.tar.gz 18.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-iot-tunnel 0.12
File Interpreter ABI Platform
aws_iot_tunnel-0.12-py3-none-any.whl Python 3 none any Details

Total release size: 30.0 kB

Release files / aws_iot_tunnel-0.12.tar.gz

Download URL aws_iot_tunnel-0.12.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
493cbc65057c34894d2e1f2db5bf9920de606af37d9e54d94a08f6004e8b3802
BLAKE2b-256 checksum
How to use checksums
7b3354d23cad93aff234c021c6d466fc1142437feca5a391e4b37a7751d99c7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

Release files / aws_iot_tunnel-0.12-py3-none-any.whl

Download URL aws_iot_tunnel-0.12-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b274af9e72bee080fc259504480bc79b9633a07072dbf31409d82f1bfacfdde1
BLAKE2b-256 checksum
How to use checksums
999473c97d23baa9b74ea33d685e0c42c3eb9576eee773b65bb5dd567f91a212
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.12 This release

2 release files

0.11

2 release files

0.9

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page