簡體   English   中英

Can an AWS Lambda function call another normal python function from a python file?

[英]Can an AWS Lambda function call another normal python function from a python file?

我有一個 python 文件,它有很多功能。 For each function, I have to create a respective AWS lambda function so that the AWS Lambda function calls that normal function. 有沒有辦法做到這一點? 對於前->

正常 function:

def add_num(input1, input2):
   return input1 + input2

現在我想要一個 AWS lambda function 來調用上面的 function。 我怎樣才能做到這一點?

是的,你可以

有兩個流行的選項可以使您的自定義庫可用於您的 lambda function。

  1. 將函數的自定義庫與部署 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. 您可以將 package 直接上傳到 Lambda,也可以使用 Amazon S3 存儲桶,然后將其上傳到 Lambda。

  1. 使用您的庫和您需要的其他依賴項創建lambda 層 這種方法優於 1 的優點是您可以跨多個 lambda function重用公共代碼

通過層,您可以在 function 中使用庫,而無需將它們包含在部署 package 中。

使用上述任一選項,您可以像通常在本地工作站上一樣導入庫 例如:

import myutils

def handler_name(event, context): 

    some_value = myutils.add_num(1, 2)
    ...
    return some_value

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM