Skip to content

Instantly share code, notes, and snippets.

@kisst
Created August 3, 2019 15:47
Show Gist options
  • Save kisst/540bccb677922346d0e53ca73bca9c0a to your computer and use it in GitHub Desktop.
Save kisst/540bccb677922346d0e53ca73bca9c0a to your computer and use it in GitHub Desktop.
Medium ...
import lambdalayer.mymodule
def lambda_handler(event, context)
mymodule.offloadedcode(event, context)
# to be able to reload existing imports
import importlib
# add my pip location
sys.path.insert(0, '/tmp/upload')
# now import the core
import botocore
# reload it
importlib.reload(botocore)
# and now ready to import boto3
import boto3
def install_with_pip(packages):
"""
Install pip package into /tmp folder
"""
print(" -- Installing pip packages")
logfile = open("/tmp/pip-install.log", "wb")
for package in packages:
print(" ---- Installing {}".format(package))
subprocess.check_call([
sys.executable, '-m', 'pip', 'install',
'--upgrade', '-t', PKG_DIR, package], stdout=logfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment