title: Test AWS lambda function via cli
body: <p>I want to test a lambda function via CLI instead of the AWS Management console. (Looking to automate function testing by making a bash script)</p>
  
  <p>I've read the documentation: <a href="http://docs.aws.amazon.com/cli/latest/reference/lambda/invoke.html" rel="nofollow noreferrer">http://docs.aws.amazon.com/cli/latest/reference/lambda/invoke.html</a></p>
  
  <p>I am trying to invoke the lambda function with a json event payload. My bashcode looks like this: </p>
  
  <pre><code>#!/bin/bash
  
  name="arn:aws:lambda:euwest1:100000000000:function:foo"
  invoketype="Event"
  payload="{'account':'100261334439', 'region':'eu-west-1', 'detail-type':'Scheduled Event', 'source':'aws.events', 'time':'2017-07-16T03:00:00Z', 'id':'178710aa-6871-11e7-b6ef-e9b95183cfc9', 'resources':['arn:aws:events:eu-west-1:100000000000:rule/run_everyday']}"
  
  aws lambda invoke --function-name "$name" --invocation-type "$invoketype" --payload "$payload" testresult.log
  </code></pre>
  
  <p>I am getting the error:</p>
  
  <pre><code>An error occurred (InvalidRequestContentException) when calling the Invoke operation: Could not parse request body into json: Unexpected character ('a'
  (code 97)): was expecting double-quote to start field name at [Source: [B@7ac4c2fa; line: 1, column: 3]
  </code></pre>
  
  <p>I believe I am providing the payload in wrong format, but the documentation has no example, it just says that the datatype is 'blob'. I did some searching but only found info on BLOB (binary large object), but I'm pretty sure this is not what the documentation is referring to.</p>
  
  <p>I have tried without the outer double quotes and replacing all the single quotes with double quotes, but all of these give the same error.</p>