简体   繁体   English

Python从带有boto3错误的代码中调用我的AWS Lambda

[英]Python call my AWS lambda from code with boto3 error

In my project i have to create a py that call a lambda function passing body parameters, i write this code: 在我的项目中,我必须创建一个调用lambda函数的py,以传递身体参数,我编写以下代码:

import boto3
import json
import base64

client = boto3.client(‘lambda’)
d = {'calID': '92dqiss5bg87etcqeeamlmob2g@group.calendar.google.com', 'datada': '2017-12-22T16:40:00+01:00', 'dataa': '2017-12-22T17:55:00+01:00', 'email': 'example@hotmail.com'}
s = json.dump(d)
s64 = base64.b64encode(s.encode('utf-8'))

response = client.invoke(
    FunctionName='arn:aws:lambda:eu-west-1:13737373737:function:test',
    InvocationType='RequestResponse',
    LogType='None',
    ClientContext='None',
    Payload=s64
)

but when response run this error is generated: 但是在响应运行时会生成此错误:

InvalidRequestContentException: An error occurred (InvalidRequestContentException) when calling the Invoke operation: Could not parse request body into json: Unrecognized token 'eyJjYWxJRCI6ICI5MmRxaXNzNWJnODdldGNxZWVhbWxtb2IyZ0Bncm91cC5jYWxlbmRhci5nb29nbGUuY29tIiwgImRhdGFkYSI6ICIyMDE3LTEyLTIyVDE2OjQwOjAwKzAxOjAwIiwgImRhdGFhIjogIjIwMTctMTItMjJUMTc6NTU6MDArMDE6MDAiLCAiZW1haWwiOiAibHVjYV9ncmV6eml4eEBob3RtYWlsLmNvbSJ9': was expecting ('true', 'false' or 'null') at [Source: [B@4587098d; InvalidRequestContentException:发生错误(InvalidRequestContentException)调用调用运行时:无法解析请求主体为JSON:无法识别的记号“eyJjYWxJRCI6ICI5MmRxaXNzNWJnODdldGNxZWVhbWxtb2IyZ0Bncm91cC5jYWxlbmRhci5nb29nbGUuY29tIiwgImRhdGFkYSI6ICIyMDE3LTEyLTIyVDE2OjQwOjAwKzAxOjAwIiwgImRhdGFhIjogIjIwMTctMTItMjJUMTc6NTU6MDArMDE6MDAiLCAiZW1haWwiOiAibHVjYV9ncmV6eml4eEBob3RtYWlsLmNvbSJ9”:期待(“真”,“假”或“空”)在[来源:[B @ 4587098d; line: 1, column: 481] 行:1,列:481]

what this mean? 这是什么意思?

Many thanks in advance 提前谢谢了

The error is because of the following parameter: 该错误是由于以下参数引起的:

ClientContext='None',

From the docs : 文档

ClientContext (string) -- ClientContext(字符串)-

Using the ClientContext you can pass client-specific information to the Lambda function you are invoking. 使用ClientContext可以将特定于客户端的信息传递给您要调用的Lambda函数。 You can then process the client information in your Lambda function as you choose through the context variable. 然后,您可以通过上下文变量进行选择,从而在Lambda函数中处理客户信息。 For an example of a ClientContext JSON, see PutEvents in the Amazon Mobile Analytics API Reference and User Guide . 有关ClientContext JSON的示例,请参阅Amazon Mobile Analytics API参考和用户指南中的PutEvents

The ClientContext JSON must be base64-encoded and has a maximum size of 3583 bytes. ClientContext JSON必须是base64编码的,最大大小为3583字节。

You do not need the ClientContext parameter here at all. 您根本不需要在这里的ClientContext参数。 Simply invoke as follows: 只需调用如下:

response = client.invoke(
    FunctionName='arn:aws:lambda:eu-west-1:13737373737:function:test',
    LogType='None',
    Payload=json.dumps(d)
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM