這是代碼
message = {
"default":"Sample fallback message",
"http":{
"data":[
{
"type":"articles",
"id":"1",
"attributes":{
"title":"JSON:API paints my bikeshed!",
"body":"The shortest article. Ever.",
"created":"2015-05-22T14:56:29.000Z",
"updated":"2015-05-22T14:56:28.000Z"
}
}
]
}
}
message_as_json = json.dumps(message)
response = sns_client.publish(TopicArn = "arn:aws:sns:us-east-1:MY-ARN",
Message = message_as_json, MessageStructure = "json")
print(response)
為了進行測驗,我使用 ngrok 將本地主機(運行我的 Flask 應用程式)連接到網路并創建了一個 http 訂閱。
當我發布訊息時,我只能看到其中的默認訊息。
知道為什么會這樣嗎?
uj5u.com熱心網友回復:
您需要http根據 AWS boto3 docs將鍵的值指定為簡單的 JSON 字串值:
與支持的傳輸協議對應的 JSON 物件中的鍵必須具有簡單的 JSON 字串值。
非字串值將導致鍵被忽略。
import json
import boto3
sns_client = boto3.client("sns")
message = {
"default": "Sample fallback message",
"http": json.dumps(
{
"data": [
{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON:API paints my bikeshed!",
"body": "The shortest article. Ever.",
"created": "2015-05-22T14:56:29.000Z",
"updated": "2015-05-22T14:56:28.000Z",
},
}
]
}
),
}
response = sns_client.publish(
TopicArn="arn:aws:sns:us-east-1:MY-ARN", Message=json.dumps(message), MessageStructure="json"
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/354340.html
上一篇:COPYINTO陳述句未將檔案型別生成為.csv-Snowflake、S3
下一篇:中間有固定字串的AWSS3路徑
