如何将列表传递到 SNS 的消息中?

How to pass a list into message of SNS?

我正在尝试使用 python 发送 SNS。它工作正常。但是我想将一个列表传递到 SNS 的消息正文中。怎么做?

我试过了,但没有用。

list = [('9',), ('8',), ('7',), ('6',), ('5',), ('4',), ('3',), ('23',), ('22',), ('21',), ('20',), ('2',), ('19',), ('18',), ('17',), ('16',), ('15',), ('14',), ('13',), ('12',), ('11',), ('10',), ('0',)]

message = { "source": "datapipeline",
            "application_nm": "omni",
            "severity": "2",
            "batch_run_start_dttm": "$actualStartTime",
            "batch_run_end_dttm": "actualEndTime",
            "batch_run_status_cd": "failed",
            "job_orchestration_id": "NA",
            "stage_nm": "NA",
            "stage_start_dttm": "NA",
            "stage_end_dttm": "NA",
            "stage_status_cd":  "failed",
            "job_run_id": "NA",
            "source_nm": "NA",
            "target_nm": "NA",
            "source_details": "NA",
            "target_details": "NA",
            "msg": "These mentioned hours having difference more than 50% from previous week:" +"%s"  ,
            "counts":"0",
            "notes": "After hourly comparison check, the above mentioned hours is having difference more than 50%"
          } %list

try:
    response = client.publish(
    TargetArn=sns_arn,
    Subject = 'Hourly comaprison mismatch',
    Message=json.dumps({'default': json.dumps(message)}),
    MessageStructure='json'
    )
    #return 'servicenow'
except Exception as e:
    return e
    print(e)
    print('SNS is throwing error!')

试图通过列表值 is msg with %s。但是抛出一个错误。如何将该列表值传递到 SNS 的 JSON 格式消息正文中?

试试这个:

message = { "source": "datapipeline",
            "application_nm": "omni",
            "severity": "2",
            "batch_run_start_dttm": "$actualStartTime",
            "batch_run_end_dttm": "actualEndTime",
            "batch_run_status_cd": "failed",
            "job_orchestration_id": "NA",
            "stage_nm": "NA",
            "stage_start_dttm": "NA",
            "stage_end_dttm": "NA",
            "stage_status_cd":  "failed",
            "job_run_id": "NA",
            "source_nm": "NA",
            "target_nm": "NA",
            "source_details": "NA",
            "target_details": "NA",
            "msg": "These mentioned hours having difference more than 50% from previous week:" +"%s"  ,
            "counts":"0",
            "notes": "After hourly comparison check, the above mentioned hours is having difference more than 50%",
            "list": list # this is how to do it
          }

顺便说一下,将变量命名为 "list" 是一个非常糟糕的主意,它与内置的 list() 函数冲突。