Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws lambda: invoke with payload from cli

I'm trying to invoke my lambda using aws cli:

$ aws lambda invoke \
    --function-name soc-update-dynamodb-java \
    --invocation-type Event \
    --payload file://invoke-payload.json \
   response.json

However, I'm getting this message:

An error occurred (InvalidRequestContentException) when calling the Invoke operation: Could not parse request body into json: Invalid UTF-8 middle byte 0x28 at [Source: (byte[])"E�(�����U�슉���ޞԨ��k.....

payload.json content is a s3 event-like json:

{
"Records": [
  {
    "eventVersion": "2.0",
    "eventSource": "aws:s3",
    "awsRegion": "eu-central-1",
    "eventTime": "1970-01-01T00:00:00.000Z",
    "eventName": "ObjectCreated:Put",
    "userIdentity": {
      "principalId": "EXAMPLE"
    },
    "requestParameters": {
      "sourceIPAddress": "127.0.0.1"
    },
    "responseElements": {
      "x-amz-request-id": "EXAMPLE123456789",
      "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH"
    },
    "s3": {
      "s3SchemaVersion": "1.0",
      "configurationId": "testConfigRule",
      "bucket": {
        "name": "soc-connect",
        "ownerIdentity": {
          "principalId": "EXAMPLE"
        },
        "arn": "arn:aws:s3:::example"
      },
      "object": {
        "key": "example.key",
        "size": 1024,
        "eTag": "0123456789abcdef0123456789abcdef",
        "sequencer": "0A1B2C3D4E5F678901"
      }
    }
  }
]
}

I'm able to execute it from aws web console using this event, but I have problem trying to invoke it using aws cli.

I've get encoding from invoke-payload.json:

$ file -i invoke-payload.json 
invoke-payload.json: text/plain; charset=us-ascii

As you can see, encoding is us-ascii.

EDIT

I've also tried to send payload embedded on command. As you can see on image, I'm getting the same message:

enter image description here

Any ideas?

like image 926
Jordi Avatar asked Apr 01 '20 11:04

Jordi


Video Answer


1 Answers

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

like image 118
Max Tarpini Avatar answered Sep 18 '22 17:09

Max Tarpini