In my project i have to create a py that call a lambda function passing body parameters, i write this code:
import boto3
import json
import base64
client = boto3.client(‘lambda’)
d = {'calID': '[email protected]', 'datada': '2017-12-22T16:40:00+01:00', 'dataa': '2017-12-22T17:55:00+01:00', 'email': '[email protected]'}
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; line: 1, column: 481]
what this mean?
Many thanks in advance
The error is because of the following parameter:
ClientContext='None',
From the docs:
ClientContext (string) --
Using the
ClientContext
you can pass client-specific information to the Lambda function you are invoking. You can then process the client information in your Lambda function as you choose through the context variable. For an example of aClientContext
JSON, see PutEvents in the Amazon Mobile Analytics API Reference and User Guide .The ClientContext JSON must be base64-encoded and has a maximum size of 3583 bytes.
You do not need the ClientContext
parameter here at all. Simply invoke as follows:
response = client.invoke(
FunctionName='arn:aws:lambda:eu-west-1:13737373737:function:test',
LogType='None',
Payload=json.dumps(d)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With