Deploy Python Lambda functions with .zip file archives - AWS Lambda
AWS services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with AWS services in China.

Deploy Python Lambda functions with .zip file archives

Your AWS Lambda function's code consists of scripts or compiled programs and their dependencies. You use a deployment package to deploy your function code to Lambda. Lambda supports two types of deployment packages: container images and .zip files.

To create a deployment package, you can use a built-in .zip file archive utility or any other .zip file utility (such as 7zip) for your command line tool. Note the following requirements for using a .zip file as your deployment package:

  • The .zip file must contain your function's code and any dependencies used to run your function's code (if applicable) on Lambda. If your function depends only on standard libraries, or AWS SDK libraries, you don't need to include these libraries in your .zip file. These libraries are included with the supported Lambda runtime environments.

  • The .zip file must be less than 50 MB. If it's larger than 50 MB, we recommend uploading it to an Amazon Simple Storage Service (Amazon S3) bucket.

  • The .zip file can't contain libraries written in C or C++. If your .zip file contains C-extension libraries, such as the Pillow (PIL) or numpy libraries, we recommend using the AWS Serverless Application Model (AWS SAM) command line interface (CLI) to build a deployment package.

This section describes how to create a .zip file as your deployment package, and then use the .zip file to deploy your function code to Lambda using the AWS Command Line Interface (AWS CLI).

Prerequisites

The AWS CLI is an open-source tool that enables you to interact with AWS services using commands in your command line shell. To complete the steps in this section, you must have the following:

What is a runtime dependency?

A deployment package is required to create or update a Lambda function with or without runtime dependencies. The deployment package acts as the source bundle to run your function's code and dependencies (if applicable) on Lambda.

A dependency can be any package, module or other assembly dependency that is not included with the Lambda runtime environment for your function's code. For more information, see What is a runtime dependency?.

The following example describes a Lambda function without runtime dependencies:

  • If your function's code is in Python 3.8, and it depends only on standard Python math and logging libraries, you don't need to include the libraries in your .zip file. These libraries are included with the python3.8 runtime.

  • If your function's code depends only on the AWS SDK for Python (Boto3), you don't need to include the boto3 library in your .zip file. These libraries are included with the python3.8 runtime.

For a complete list of AWS SDKs, see Tools to Build on AWS.