Running an AWS Lambda Command from Windows Shells

I have been using Linux as my primary OS for quite a while and was surprised when the simple aws lambda invoke command didn’t work in Windows 10.

In Linux, I have been using -

aws lambda invoke --function-name PersonToUpper --cli-binary-format raw-in-base64-out --payload '{ "firstName": "alan", "lastName": "adams" }' response.json

It executes, gives a status, and creates the response.json file.

{
    "StatusCode": 200,
    "ExecutedVersion": "$LATEST"
}

Command Prompt

If I try the above in the command prompt I get -

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: lastName:, adams, }', response.json, alan,

A bit of escaping is needed, and note the " opening and closing the Json -

aws lambda invoke --function-name PersonToUpper --cli-binary-format raw-in-base64-out --payload "{ \"firstName\": \"alan\", \"lastName\": \"adams\" }" response.json

Now it works.

PowerShell

If I run the original command that works Linux in PowerShell I get a different error -

An error occurred (InvalidRequestContentException) when calling the Invoke operation: Could not parse request body into json: Could not parse payload into json: Unexpected character ('f' (code 102)): was expecting double-quote to start field name
 at [Source: (byte[])"{ firstName: alan, lastName: adams }"; line: 1, column: 4]

The escaping I used in the Command Prompt doesn’t work, the double quote at the start of the Json must be changed to a single quote.

aws lambda invoke --function-name PersonToUpper --cli-binary-format raw-in-base64-out --payload '{ \"firstName\": \"alan\", \"lastName\": \"adams\" }' response.json

WSL Ubuntu and Git Bash

The original command from Linux works fine in both of these.

aws lambda invoke --function-name PersonToUpper --cli-binary-format raw-in-base64-out --payload '{ "firstName": "alan", "lastName": "adams" }' response.json
comments powered by Disqus

Related