Skip to main content

run code or subprocess on aws lambda invoke context

Project description

lambda-run

run python code or shell commands on aws lambda invoke context

install:

# use bare package for production
$ pip install lambda-run

# use to install dev dependencies
# needed to execute commands from cli 
$ pip install lambda-run[cli]

usage:

wrap your lambda function like this:

import lambda_run

# wrapping will catch 'lambdaRun' events
# otherwise it will pass the event forward
@lambda_run.wrap_handler
def lambda_handler(event, context):
    # your regular lambda handler...
    print(event, context) 
    return 'OK' 

execute commands from cli:

# set AWS env vars for boto3
export AWS_PROFILE=profile AWS_DEFAULT_REGION=eu-west-1

# Usage: lambda-run [OPTIONS] FUNCTION_NAME [PAYLOAD]

# attach payload directly as last argument
lambda-run -m python my-lambda 'import sys; print(sys.path)'

# or by posix pipe/redirect, for example: 
# pipe it
echo 'import sys; print(sys.path)' | lambda-run -m python my-lambda 

# oneliner redirect
lambda-run -m shell my-lambda <<<'python manage.py createsuperuser'

# or multiline
lambda-run -m python my-lambda <<EOF
for i in range(10):
    print(i)
EOF

# or file content
lambda-run -m shell my-lambda <bash-script.sh

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lambda-run-0.0.3.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distribution

lambda_run-0.0.3-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page