Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Created February 22, 2021 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruanbekker/89575c5b318bea1a240c83df9b6b1738 to your computer and use it in GitHub Desktop.
Save ruanbekker/89575c5b318bea1a240c83df9b6b1738 to your computer and use it in GitHub Desktop.
Update AWS Lambda Function with Dependencies in Python using a Deployment Package

Change into our working directory:

$ mkdir -p myworkdir/src 
$ cd myworkdir

Create a virtual env:

virtualenv -p python3 .venv
source .venv/bin/activate

Change into the src directory:

$ cd src

Our function:

$ cat lambda_function.py
import elasticsearch

def lambda_handler(event, context)
    es_version = elasticsearch.__version__
    print(es_version)
    return  {"statusCode": 200, "body": json.dumps(body)}

Install the dependencies locally:

$ pip install elasticsearch -t .

Now our working directory will look like this:

$ tree .
.
├── lambda_function.py
├── elasticsearch
│   ├── __init__.py
....
1 directory, 2 files

Zip up the deployment package:

$ zip -r deployment_package.zip *

Update the lambda function code:

$ aws --profile dev lambda update-function-code --function-name $fn --zip-file fileb://deployment_package.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment