2017-08-01 174 views
1

我想通過CLI測試lambda函數而不是AWS管理控制檯。 (希望通過做一個bash腳本自動化功能測試)通過cli測試AWS lambda函數

我讀過的文檔:http://docs.aws.amazon.com/cli/latest/reference/lambda/invoke.html

我試圖調用一個JSON事件負載lambda函數。我bashcode看起來是這樣的:

#!/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 

我收到錯誤:

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: [[email protected]; line: 1, column: 3] 

我相信我提供的格式錯誤的有效載荷,但該文件沒有例子,它只是說,數據類型是'blob'。我做了一些搜索,但只發現BLOB(二進制大對象)的信息,但我很肯定這不是文檔所指的。

我試過沒有外雙引號,並用雙引號替換所有單引號,但所有這些給出了相同的錯誤。

回答

1

有效JSon應該有雙引號

之間的鍵和值,所以你應該有​​屬性寫成

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