[英]How could I pass arguments to invoke AWS lambda function by using python?
In my application,I will input data to invoke my lambda function,how can I do it?在我的应用程序中,我将输入数据来调用我的 lambda 函数,我该怎么做? Thanks a lot.
非常感谢。
The Payload
parameter of the invoke function might be what you are looking for. 调用函数的
Payload
参数可能就是您要查找的内容。
The format is "bytes or seekable file-like object" which means a bytes string, or an open filehandle or perhaps a BytesIO?格式是“字节或可搜索的类文件对象” ,表示字节字符串、打开的文件句柄或可能是 BytesIO?
This works for me:这对我有用:
import boto3
import json
import pprint
params = {"day": "20220410"}
client = boto3.client('lambda')
response = client.invoke(
FunctionName='my_lambda_function',
InvocationType='RequestResponse',
Payload=json.dumps(params).encode(),
)
pprint.pp(response['Payload'].read())
The lambda receives the params in the event dictionary: lambda 接收事件字典中的参数:
def my_lambda_function(event, context):
day = event['day']
Since, you have only mentioned因为,你只提到
In my application, I will input data to invoke my lambda
在我的应用程序中,我将输入数据来调用我的 lambda
I think you probably want to invoke lambda from you application.我认为您可能想从您的应用程序中调用 lambda。
For that,为了那个原因,
boto
.boto
导入 lambda。import boto3 client = boto3.client('lambda')
invoke()
to invoke a function with parameters:invoke()
调用带参数的函数:response = client.invoke( FunctionName='string', InvocationType='Event'|'RequestResponse'|'DryRun', LogType='None'|'Tail', ClientContext='string', Payload=b'bytes'|file, Qualifier='string' )
You can use official documentation to explore more Lambda boto Documentation您可以使用官方文档来探索更多Lambda boto 文档
Also,还,
Lambda Function can be invoked in following ways:可以通过以下方式调用 Lambda 函数:
Documentation: Ways to Invoke AWS Lambda Function文档: 调用 AWS Lambda 函数的方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.