Home > Net >  How to invoke with InputStream/Context payload using aws cli?
How to invoke with InputStream/Context payload using aws cli?

Time:12-27

So far, I've only covered invoking functions that take strings as input. However, in this example, the inputs are InputStreams and Contexts. Is there a way to invoke this function from the command line?

Code I am trying to invoke: https://github.com/symphoniacloud/programming-aws-lambda-book/blob/master/chapter3/src/main/java/book/ContextLambda.java

How I invoked other examples with strings as the input:

aws lambda invoke \
--invocation-type RequestResponse \
--function-name HelloWorldJava \
--payload \"world\" outputfile.txt \
--cli-binary-format raw-in-base64-out

CodePudding user response:

It turns out that I needed to use an example, any example, from the AWS Lambda test event templates in order to trigger this function to run. I chose to use the cognito-sync-trigger test event. I then ran the following in a bash script but it can also be run step by step in the terminal as well. The test event is set to the variable PAYLOAD:

#!/bin/bash
PAYLOAD=$(cat <<EOF
{
  "version": 2,
  "eventType": "SyncTrigger",
  "region": "us-east-1",
  "identityPoolId": "identityPoolId",
  "identityId": "identityId",
  "datasetName": "datasetName",
  "datasetRecords": {
    "SampleKey1": {
      "oldValue": "oldValue1",
      "newValue": "newValue1",
      "op": "replace"
    },
    "SampleKey2": {
      "oldValue": "oldValue2",
      "newValue": "newValue2",
      "op": "replace"
    }
  }
}
EOF
)
aws lambda invoke --invocation-type RequestResponse --function-name HelloWorldJava --payload "$PAYLOAD" outputfile.txt --cli-binary-format raw-in-base64-out
  • Related