從另一個 SAM 本地函數調用 AWS SAM 本地函數 (Invoke AWS SAM local function from another SAM local function)


問題描述

從另一個 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 umangMistryBOMayank Raj)

參考文件

  1. Invoke AWS SAM local function from another SAM local function (CC BY‑SA 2.5/3.0/4.0)

#Python #yaml #serverless #amazon-web-services #aws-lambda






相關問題

如何從控制台中導入的文件中訪問變量的內容? (How do I access the contents of a variable from a file imported in a console?)

在 python 3.5 的輸入列表中添加美元符號、逗號和大括號 (Adding dollar signs, commas and curly brackets to input list in python 3.5)

為 KeyError 打印出奇怪的錯誤消息 (Strange error message printed out for KeyError)

django 1.9 中的 from django.views.generic.simple import direct_to_template 相當於什麼 (What is the equivalent of from django.views.generic.simple import direct_to_template in django 1.9)

查詢嵌入列表中的數組 (Querying for array in embedded list)

如何在 Python 中搜索子字符串是否在二進製文件中? (How to search if a substring is into a binary file in Python?)

為什麼要避免 while 循環? (Why avoid while loops?)

使用python的json模塊解析json請求 (Parse a json request using json module of python)

為什麼使用 py2app 模塊創建 mac 文件時出現錯誤? (Why i am getting Error when creating mac file using py2app module?)

當 python 線程在網絡調用(HTTPS)中並且發生上下文切換時會發生什麼? (What happens when the python thread is in network call(HTTPS) and the context switch happens?)

如何繪製一條帶斜率和一個點的線?Python (How to plot a line with slope and one point given? Python)

Pickle 找不到我不使用的模塊? (Pickle can't find module that I am not using?)







留言討論