問題描述
從另一個 SAM 本地函數調用 AWS SAM 本地函數 (Invoke AWS SAM local function from another SAM local function)
我正在嘗試創建一個具有多個 AWS 無服務器函數的 AWS SAM 應用程序。
該應用程序有 1 個 template.yaml 文件,其中包含 2 個不同的無服務器 lambda 函數的資源,例如“Consumer Lambda”。和“工人 Lambda”。消費者以 5 分鐘的速度被觸發。消費者使用 boto3 庫來觸發 worker lambda 函數。當工作 lambda 部署在 AWS 上時,此代碼有效。
但我想使用 Sam 本地調用“消費者”在本地測試這兩個函數。它調用“Worker”;也在本地。
這是 YAML 文件的屏幕截圖:
docs):
sam local start‑lambda
Now you can point your AWS resource client to port 3001 and trigger the functions locally.
For eg. If you are doing this on Python, it can be acheived in the following way with boto3:
boto3
# Create a lambda client
lambda_client = boto3.client('lambda',
region_name="<localhost>",
endpoint_url="<http://127.0.0.1:3001>",
use_ssl=False,
verify=False)
# Invoke the function
lambda_client.invoke(FunctionName=<function_name>,
Payload=<lambda_payload>)
(by umangMistryBO、Mayank Raj)