[英]How do I POST a JSON file as MessageBody for Amazon SQS?
我在本地運行ElasticMQ來模擬 Amazon SQS,並且我想將 JSON 文件作為 MessageBody 發送。 這是一個有效的示例請求:
$ curl 'http://localhost:9324/queue/foo?Action=SendMessage&MessageBody={"action":"hey"}'
<SendMessageResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/">
<SendMessageResult>
[...]
如果我想發送一個大的 JSON 文件,將其作為 POST 會更有意義,如下所示:
$ curl 'http://localhost:9324/queue/foo?Action=SendMessage' -X POST \
-H "Content-Type: application/json" --data @./bigdata.json
There was an internal server error.
有沒有辦法使這項工作?
這是一個舊的,但我最近在這方面做得不夠,想添加我發現的內容。
如果您將Content-Type
設置為text/plain
則消息會成功,這與 json 數據負載非常不直觀。
$ curl -X "POST" "https://sqs.us-east-1.amazonaws.com/136525823465/rfidsqs?Action=SendMessage" -H 'Content-Type: text/plain' -d '{"testKey1": 123456,"testKey2": "5sUXJYodEUVvQwVT"}'
回應
<SendMessageResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/">
<SendMessageResult>
<MessageId>ba2f6498-0e6b-48cd-bd8f-027d911082b6</MessageId>
<MD5OfMessageBody>4c8132a52a4e6f0bb5ecbe758502c69f</MD5OfMessageBody>
</SendMessageResult>
<ResponseMetadata>
<RequestId>ddc02593-8757-5d0b-a780-72183ae5f517</RequestId>
</ResponseMetadata>
</SendMessageResponse>
我不認為這是可能的。 根據文檔和實驗,它接受的唯一內容類型是表單application/x-www-form-urlencoded
,這意味着主體只能有key=value
對。 您可能必須提供一個作為實際 JSON 正文的值
cbongiorno at wa-christianb-mbp in ~/dev/core-infra on anchore-update [+!$]
$ curl -H "content-type: application/json" -d '{"id":123}' https://sqs.us-east-1.amazonaws.com/123456789/christian-anchore-test?Action=SendMessage | xmllint --format -
<?xml version="1.0"?>
<ErrorResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/">
<Error>
<Type>Sender</Type>
<Code>MissingParameter</Code>
<Message>The request must contain the parameter MessageBody.</Message>
<Detail/>
</Error>
<RequestId>9452510a-0a40-5f68-8319-05cf9ed70beb</RequestId>
</ErrorResponse>
這似乎是一個極其短視的決定,但從接受的參數可以看出,只有 1 個 URL,它被用作控制信號 URL。 它非常像 SOAP,但以一種自定義/黑客攻擊的方式進行。
我現在也有同樣的掙扎。 根據您嘗試執行的操作,您可以創建一個私有 API 網關並連接一個 lambda 來重新映射它。 但無論你如何切片,你都必須重新映射它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.