Skip to content

Instantly share code, notes, and snippets.

@thomelane
Created May 10, 2020 23:25
Show Gist options
  • Save thomelane/d1b2eeac9ad10476c13bc5044c381b13 to your computer and use it in GitHub Desktop.
Save thomelane/d1b2eeac9ad10476c13bc5044c381b13 to your computer and use it in GitHub Desktop.
Runtime install of PyPI package inside AWS Lambda function
import tempfile
from pathlib import Path
import subprocess
import sys
tmp_path = Path(tempfile.gettempdir())
packages = ['crhelper']
for package in packages:
subprocess.check_call([
sys.executable, "-m", "pip", "install", "--target={}".format(tmp_path), package
])
sys.path.append(str(tmp_path))
import crhelper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment