Yes, you can.
There are two popular option to make your custom libraries available for your lambda function.
- Bundle your function's custom libraries with your deployment package:
You need to create a deployment package if you use the Lambda API to manage functions, or if you need to include libraries and dependencies other than the AWS SDK. You can upload the package directly to Lambda, or you can use an Amazon S3 bucket, and then upload it to Lambda.
- Create a lambda layer with your libraries and other dependencies you require. The advantage of this approach over 1 is that you can reuse common code across multiple lambda function:
With layers, you can use libraries in your function without needing to include them in your deployment package.
With either of the above options, you can import your libraries as you usually do on a local workstation. For example:
import myutils
def handler_name(event, context):
some_value = myutils.add_num(1, 2)
...
return some_value