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 Overflow
🌐
Amazon Web Services
docs.aws.amazon.com › cli › latest › reference › lambda › invoke.html
invoke — AWS CLI 2.34.36 Command Reference
The following invoke example invokes the my-function function asynchronously. The cli-binary-format option is required if you’re using AWS CLI version 2. For more information, see AWS CLI supported global command line options in the AWS Command Line Interface User Guide. aws lambda invoke \ --function-name my-function \ --invocation-type Event \ --cli-binary-format raw-in-base64-out \ --payload '{ "name": "Bob" }' \ response.json
Discussions

lambda invoke: Allow specifying a payload from a file
The lambda invoke command currently has the --payload CLI arg. The docs state that this must be a JSON "blob". If one wishes to pass secrets to a Lambda function this forces the user to p... More on github.com
🌐 github.com
10
August 8, 2019
lambda invoke --payload documentation is not up to date.
Describe the issue Hello Documentation for v1 and v2 are the same but behavior is different. versions aws --version #aws-cli/2.13.12 Python/3.11.4 Linux/5.15.90.1-microsoft-standard-WSL2 exe/x86_64... More on github.com
🌐 github.com
5
August 24, 2023
How do I invoke lambda with payload?
Can I assume you passed the unescaped JSON in single quotes? More on reddit.com
🌐 r/awslambda
2
1
May 16, 2020
How to trigger a lambda via an API Request with JSON input?
The inbound event is a different type when calling from EB versus API Gateway, so I’m guessing the 500 is possibly your code not handling the new event type. More on reddit.com
🌐 r/aws
9
5
August 6, 2023
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › code examples for lambda using aws sdks › basic examples for lambda using aws sdks › actions for lambda using aws sdks › use invoke with an aws sdk or cli
Use Invoke with an AWS SDK or CLI - AWS Lambda
The following invoke example invokes the my-function function asynchronously. The cli-binary-format option is required if you're using AWS CLI version 2. For more information, see AWS CLI supported global command line options in the AWS Command Line Interface User Guide. aws lambda invoke \ --function-name my-function \ --invocation-type Event \ --cli-binary-format raw-in-base64-out \ --payload '{ "name": "Bob" }' \ response.json
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › api reference › actions › invoke
Invoke - AWS Lambda
By default, Lambda invokes your ... passes the ClientContext object to your function for synchronous invocations only. For synchronous invocations, the maximum payload size is 6 MB....
🌐
Bobby Hadz
bobbyhadz.com › blog › aws-cli-invoke-lambda-functions
Invoke Lambda Functions with AWS CLI - Complete Guide | bobbyhadz
February 26, 2024 - All the other scenarios are the same as invoking a Lambda function synchronously: To invoke the function with a file, store valid json in a file on your local file system and prefix the --payload parameter with file:// Here is the event.json ...
🌐
Cargo-lambda
cargo-lambda.info › commands › invoke.html
Cargo Lambda Invoke | Cargo Lambda
2 weeks ago - cargo lambda invoke basic-lambda --data-file examples/my-payload.json · The --data-example flag allows you to fetch an example payload from the aws-lambda-events repository, and use it as your request payload.
🌐
GitHub
github.com › aws › aws-cli › issues › 4389
lambda invoke: Allow specifying a payload from a file · Issue #4389 · aws/aws-cli
August 8, 2019 - For example --payload-from /path/to/payload.json. Alternatively, could use cURL's approach where if the first character is @, interpret it as a path: --payload @/path/to/payload.json.
Author   jdufresne
Find elsewhere
🌐
GitHub
github.com › aws › aws-cli › issues › 8132
lambda invoke --payload documentation is not up to date. · Issue #8132 · aws/aws-cli
August 24, 2023 - For example, --payload file://payload.json . ... # aws lambda invoke --function-name "test-lambda" --payload "$(echo '{"test":"yes"}' |base64)" file_out --log-type Tail --query 'LogResult' --output text --profile=mfa-coo --region=eu-west-1 |base64 ...
Author   thenger
🌐
AWS
docs.aws.amazon.com › aws sdk for java › developer guide for version 2.x › calling aws services from the aws sdk for java 2.x › invoke, list, and delete aws lambda functions
Invoke, list, and delete AWS Lambda functions - AWS SDK for Java 2.x
The following code example demonstrates how to invoke a Lambda function. public static void invokeFunction(LambdaClient awsLambda, String functionName) { InvokeResponse res = null ; try { //Need a SdkBytes instance for the payload String json = "{\"Hello \":\"Paris\"}"; SdkBytes payload = SdkBytes.fromUtf8String(json) ; //Setup an InvokeRequest InvokeRequest request = InvokeRequest.builder() .functionName(functionName) .payload(payload) .build(); res = awsLambda.invoke(request); String value = res.payload().asUtf8String() ; System.out.println(value); } catch(LambdaException e) { System.err.println(e.getMessage()); System.exit(1); } }
🌐
AWS
docs.aws.amazon.com › aws sdk for java › developer guide for version 1.x › aws sdk for java code examples › lambda examples using the aws sdk for java › invoking, listing, and deleting lambda functions
Invoking, Listing, and Deleting Lambda Functions - AWS SDK for Java 1.x
Function names appear as arn:aws:lambda:us-east-1:555556330391:function:HelloFunction. You can retrieve the value by looking at the function in the AWS Management Console. To pass payload data to a function, invoke the InvokeRequest object’s withPayload method and specify a String in JSON format, as shown in the following code example.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › understanding lambda function invocation methods › invoke a lambda function synchronously
Invoke a Lambda function synchronously - AWS Lambda
For more information, see AWS CLI supported global command line options in the AWS Command Line Interface User Guide for Version 2. ... The following diagram shows clients invoking a Lambda function synchronously. Lambda sends the events directly to the function and sends the function's response back to the invoker. The payload is a string that contains an event in JSON format.
🌐
TutorialsPoint
tutorialspoint.com › aws_lambda › aws_lambda_executing_and_invoking_lambda_function.htm
Executing and Invoking Lambda Function
This chapter will explain in detail about process of executing and invoking Lambda function and the steps involved in it. AWS execution depends on the configuration details added for AWS Lambda Function.
🌐
C# Corner
c-sharpcorner.com › article › passing-data-to-aws-lambda-function-and-invoking-it-using-aws-cli
Passing Data To AWS Lambda Function And Invoking It Using AWS CLI
May 25, 2020 - The payload can be specified as a filename, as shown below. ... The preceding invoke-command specifies RequestResponse as the invocation type, which returns a response immediately in response to the function execution. Alternatively, you can specify Event as the invocation type to invoke the function asynchronously. The function executes and returns the object you passed in the callback is: ... You can monitor the activity of your Lambda function in the AWS Lambda console as well.
🌐
Reddit
reddit.com › r/awslambda › how do i invoke lambda with payload?
r/awslambda on Reddit: How do I invoke lambda with payload?
May 16, 2020 -

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" }

🌐
AWS
docs.aws.amazon.com › aws sdk code examples › code library › code examples by service using aws sdks › code examples for lambda using aws sdks › basic examples for lambda using aws sdks › actions for lambda using aws sdks › use invoke with an aws sdk or cli
Use Invoke with an AWS SDK or CLI - AWS SDK Code Examples
Find the complete example and learn how to set up and run in the AWS Code Examples Repository ... /// <summary> /// Invoke a Lambda function. /// </summary> /// <param name="functionName">The name of the Lambda function to /// invoke.</param /// <param name="parameters">The parameter values that will be passed to the function.</param> /// <returns>A System Threading Task.</returns> public async Task<string> InvokeFunctionAsync( string functionName, string parameters) { var payload = parameters; var request = new InvokeRequest { FunctionName = functionName, Payload = payload, }; var response = await _lambdaService.InvokeAsync(request); MemoryStream stream = response.Payload; string returnValue = System.Text.Encoding.UTF8.GetString(stream.ToArray()); return returnValue; }
🌐
Amazon Web Services
docs.amazonaws.cn › 亚马逊云科技 › amazon lambda › developer guide › understanding lambda function invocation methods › invoke a lambda function synchronously
Invoke a Lambda function synchronously - Amazon Lambda
The following example shows how to retrieve a log ID from the LogResult field for a function named my-function. aws lambda invoke --function-name my-function out --log-type Tail
🌐
AWS
docs.aws.amazon.com › aws step functions › developer guide › integrating optimized services with step functions › invoke an aws lambda function with step functions
Invoke an AWS Lambda function with Step Functions - AWS Step Functions
{ "Comment": "A Hello World example of the Amazon States Language using Pass states", "StartAt": "Hello", "States": { "Hello": { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "Arguments": { "FunctionName": "arn:aws:lambda:region:account-id:function:echo", "InvocationType": "Event" }, "End": true } } } For asynchronous invocations of Lambda functions, the heartbeat timeout period starts immediately. When the Task result is returned, the function output is nested inside a dictionary of metadata. For example: { "ExecutedVersion":"$LATEST", "Payload":"FUNCTION OUTPUT", "SdkHttpMeta
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › understanding lambda function invocation methods › creating and managing lambda function urls › invoking lambda function urls
Invoking Lambda function URLs - AWS Lambda
For instructions on how to manually sign your requests with SigV4, see Signing AWS requests with Signature Version 4 in the Amazon Web Services General Reference Guide. If your function URL uses the NONE auth type, you don't have to sign your requests using SigV4. You can invoke your function using a web browser, curl, Postman, or any HTTP client. To test simple GET requests to your function, use a web browser. For example, if your function URL is https://abcdefg.lambda-url.us-east-1.on.aws, and it takes in a string parameter message, your request URL could look like this:
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › troubleshooting issues in lambda › troubleshoot execution issues in lambda
Troubleshoot execution issues in Lambda - AWS Lambda
January 31, 2023 - When you publish new Lambda functions in the console or using AWS SAM, the latest code version is represented by $LATEST. By default, invocations that don't specify a version or alias automatically targets the $LATEST version of your function code. If you use specific function versions or aliases, these are immutable published versions of a function in addition to $LATEST. When troubleshooting these functions, first determine that the caller has invoked the intended version or alias.