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
-
Run the docker container.
aws-iot-tunnel -t MyIoTThing -p myawsprofile -r us-west-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). |
How It Works
- boto3 SDK: The script interacts with the AWS IoT Secure Tunneling service using boto3 SDK to manage tunnels and rotate access tokens.
- Docker Integration: It runs a Docker container configured for the appropriate architecture to establish a secure tunnel to the specified IoT device.
- 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. - Explicit New Tunnels: Use
--new-tunnel/-Nto 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. - 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, sodocker ps/docker inspecttell you exactly which AWS IoT tunnel each container belongs to. The port isn't part of the name —docker psalready shows each container's port mapping, and an AWS IoT tunnel only ever supports one active local-proxy session at a time regardless of port. 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 (since only one session per tunnel can be active). 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).
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.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aws_iot_tunnel-0.11.tar.gz | 17.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aws_iot_tunnel-0.11-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.6 kB
Release files / aws_iot_tunnel-0.11.tar.gz
| Download URL | aws_iot_tunnel-0.11.tar.gz |
|---|---|
| Size | 17.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02c366bf9abd6d77b940e60bf00c26ed971a3e4944942e894be9e8d785afc9d8
|
|
BLAKE2b-256 checksum How to use checksums |
0241429bb8ee34c6f76cb5b99ae32c5fc3bd385cebe1a365b66089cc70b46038
|
| 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 logRelease files / aws_iot_tunnel-0.11-py3-none-any.whl
| Download URL | aws_iot_tunnel-0.11-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fdb6f711d1a07188cf7ee88ec5675e5c179f9efd45b30b873de227af1e8028ac
|
|
BLAKE2b-256 checksum How to use checksums |
79f1abede3cef4907696cf27f2cca29ef505ad6d25d44eccc0345e6b567ff881
|
| 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