Skip to main content

interloper

Tool to run ecs execute command in Python and in AWS Lambda. Of course, locally you can do this via the session manager plugin, but it you want to do it in lambda, it is a bit more complex.

Features

  • Run simple commands or full scripts.
  • Pass arguments into those scripts.
  • Get output back in python.

Limitations

Here are some of the current limitations.

  • Testing shell is present, but still must be completed.
    • Still needs started really.
    • Need to mock away the websocket bits.
  • This documentation.

Installation

pip install interloper

Usage

For starters, one must enable ECS exec.

Locally

./interloper.py [event]

Lambda

You can import and use the provided handlers for simple operations.

cmd_handler

from interloper import cmd_handler

... Actually, that should be sufficient. Just set the handler to main.cmd_handler or whatever your module is called in place of main.

script_handler

from interloper import script_handler

Then create an interloper.sh that suits your needs.

Custom Handler and Script

Consider needing to generate heap dumps and thread dumps from java containers. You could do so with the following.

dumper.sh

#!/usr/bin/env sh

cleanup () {
    rm -rf /tmp/dumps
    mkdir -p /tmp/dumps
}

verify_awscli () {
    if which aws >/dev/null
    then
        echo "awscli found; proceeding"
        return 0
    else
        echo "awscli not found; can't proceed"
        return 1
    fi
}

verify_jattach () {
    if which jattach >/dev/null
    then
        echo "jattach found; proceeding"
        return 0
    else
        echo "jattach not installed; installing"
        if which apk >/dev/null
        then
            apk add --no-cache jattach --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/
            return 0
        else
            echo "apk not found; can't proceed"
            return 1
        fi
    fi
}

cleanup

case "$1" in
    heap)
        if verify_jattach; then jattach $(pgrep java) dumpheap /tmp/dumps/heap.hprof; fi
        if verify_awscli; then aws s3 cp /tmp/dumps/heap.hprof s3://"$2"; fi
        ;;
    threads)
        if verify_jattach; then jattach $(pgrep java) threaddump > /tmp/dumps/threads; fi
        if verify_awscli; then aws s3 cp /tmp/dumps/threads s3://"$2"; fi
        ;;
    *)
        echo "usage: $0 {heap|threads} {key}"
esac

handler

import logging
import time

import interloper


LOG = logging.getLogger()
LOG.setLevel(logging.INFO)


def lambda_handler(event: dict, context) -> None:
    LOG.debug("event received: %s", event)
    input = interloper.Input(**event)
    key = "{}/{}/{}-{}".format(input.cluster, input.task, input.cmd, int(time.time()))
    if input.cmd == "heap":
        key += ".hprof"
    output = interloper.Interloper(
        input.task, cluster=input.cluster, container=input.container
    ).script("dumper.sh", [input.cmd, key])
    LOG.info(output)

Metadata

Release files for interloper 0.1.4

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

Source distribution (sdist)

Source distribution for interloper 0.1.4
File Size Uploaded Provenance Actions
interloper-0.1.4.tar.gz 5.6 kB Without provenance Details for interloper-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for interloper 0.1.4
File Interpreter ABI Platform Actions
interloper-0.1.4-py3-none-any.whl Python 3 none any Details for interloper-0.1.4-py3-none-any.whl

Total release size: 11.1 kB

Release files / interloper-0.1.4.tar.gz

Download URL interloper-0.1.4.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
17b02d19fef3d4d84e1555ab85eeacef17a811ea111b4b4776587490d7108854
BLAKE2b-256 checksum
How to use checksums
854ae535ae1a931018ad6d2e3f2d75c0a9dbc0ccfae2446802e45ed97dbb4d9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / interloper-0.1.4-py3-none-any.whl

Download URL interloper-0.1.4-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7fe584f97ee5ac5ea0a928bd10f1b395b9c90bd1da2dc2476e1ec803d5198d1d
BLAKE2b-256 checksum
How to use checksums
c3b307355430e0fd8ec554bb7d7fc6f4ba43fa2c3317dc1fef3d93f8aed7b123
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Security for interloper 0.1.4

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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