use the fileb:// ("file binary") syntax for the payload parameter so you don't have to run it through base64
... --payload fileb://invoke-payload.json
Answer from Max Tarpini on Stack Overflowuse the fileb:// ("file binary") syntax for the payload parameter so you don't have to run it through base64
... --payload fileb://invoke-payload.json
Invoke Lambda with simple JSON from the CLI
Here's how to test your Lambda by giving it a short JSON payload, and displaying the result in the terminal:
aws lambda invoke \
--payload '{"beer": "tasty"}' --function-name myfunc \
--cli-binary-format raw-in-base64-out \
/dev/stdout
Building on antklim's answer
lambda invoke: Allow specifying a payload from a file
lambda invoke --payload documentation is not up to date.
How do I invoke lambda with payload?
How to trigger a lambda via an API Request with JSON input?
Hi there,
I created a sample Hello World function with following python code -
import json
print('Loading function')
def lambda_handler(event, context):
#print("Received event: " + json.dumps(event, indent=2))
print("value1 = " + event['key1'])
print("value2 = " + event['key2'])
print("value3 = " + event['key3'])
return event['key1'] # Echo back the first key value
#raise Exception('Something went wrong')It works fine when I try to test it from the console. However, when I try to invoke it using AWS CLI it gives me the following error -
aws lambda invoke --function-name Hello-world --payload '{ \"key1\": \"Bob\" }' response.json
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
Unknown options: }', response.json, "Bob"What am I doing wrong here?
Thanks
PS: I have even tried the cli command with non escaped json i.e { "key1": "Bob" }