简体   繁体   English

如何在Cloudwatch中更改SNS的默认主题行?

[英]How to change the default subject line for SNS in Cloudwatch?

I have setup a rule in cloudwatch to monitor Glue ETL. 我已经在cloudwatch中设置了一个规则来监视Glue ETL。 In the state change I am sending a notification to SNS. 在状态更改中,我正在向SNS发送通知。 I have modified the input transformer to get a custom body of the email but not getting how to change the subject line of the email . 我已经修改了输入转换器,以获取电子邮件的自定义主体,但没有获取如何更改电子邮件的主题行。 It still giving the default " AWS Notification Message " 它仍然给出默认的“ AWS Notification Message

My Input transformer : 我的输入变压器:

{"state":"$.detail.state"}

"The JOB has changed state to <state>."

设置“详细类型”:“胶粘剂ETL状态更改通知”,您可能需要查看https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatch-Events-Input-Transformer-Tutorial.html

Transformer (no way Jose) As far as I can tell there is currently no way to control the email subject with a transformer. 变压器 (何塞,何塞)据我所知,目前尚无办法使用变压器控制电子邮件主题。 Typically you will control the notification body for a rule through the transformer which modifies the input json message (eg in the case of a build https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html#sample-build-notifications-ref ). 通常,您将通过转换器控制规则的通知主体,该转换器会修改输入的json消息(例如,在构建https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications的情况下) .html#sample-build-notifications-ref )。 Based on what I see in the documentation this only modifies part of the body embedded between the header and the footer of the email payload. 根据我在文档中看到的内容,这仅修改了嵌入在电子邮件有效负载的页眉和页脚之间的正文部分。

JSON (also not possible) 1. Since all notifications are generated with an API call with json payload you can experiment and configure. JSON (也是不可能的)1.由于所有通知都是通过具有JSON负载的API调用生成的,因此您可以进行实验和配置。 Using the CLI you can specify a json format using --message-structure attribute. 使用CLI可以使用--message-structure属性指定json格式。 However the subject is not part of the json payload itself and is sent as a separate parameter "--subject" (see example below) you won't be able to configure that unless they either modify the UI or the json payload. 但是,主题不是json负载本身的一部分,而是作为单独的参数“ --subject”发送的(请参见下面的示例),除非他们修改UI或json负载,否则您将无法对其进行配置。 2.In order to exercise greater control over your output you might have to use JSON (select "Constant (JSON text)") which is documented for mobile messaging https://docs.aws.amazon.com/sns/latest/dg/mobile-push-send-custommessage.html but not very well for HTTP https://docs.aws.amazon.com/sns/latest/dg/sns-message-and-json-formats.html but decent for the CLI https://docs.aws.amazon.com/cli/latest/reference/sns/publish.html 3. You can go to the console https://console.aws.amazon.com/sns/v2/ and click on "Publish a Message" which allows you to specify a subject. 2.为了更好地控制您的输出,您可能必须使用记录在移动消息中的JSON(选择“常量(JSON文本)”) https://docs.aws.amazon.com/sns/latest/dg /mobile-push-send-custommessage.html,但对于HTTP https://docs.aws.amazon.com/sns/latest/dg/sns-message-and-json-formats.html来说效果不是很好,但对于CLI来说却很不错https://docs.aws.amazon.com/cli/latest/reference/sns/publish.html 3.您可以转到控制台https://console.aws.amazon.com/sns/v2/并单击“发布消息”允许您指定主题。 Notice that there is a "JSON message generator" but that's only for the body. 请注意,这里有一个“ JSON消息生成器”,但这仅用于主体。

Coding Workaround (possible ...kinda) If you feel really determined you can explore a workaround: look at the API and figure out what call is equivalent to sending a call which includes a subject. 编码解决方法 (可能...有点)如果您真的有决心,可以探索一种解决方法:查看API,找出什么调用等效于发送包含主题的调用。 Create a lambda function that executes that call. 创建一个执行该调用的lambda函数。 From the rule invoke the lambda :-) and you are done. 从规则中调用lambda :-)即可完成操作。 If there is will, there is a way... 如果有意愿,有办法...

Notes: 笔记:

aws sns publish --topic-arn arn:aws:sns:us-east-1:652499160872:DP-Build --message-structure json --subject "Test Build subject" --message "{ \\"default\\":\\"Foo\\", \\"email\\":\\"Bar\\"}" aws sns publish --topic-arn arn:aws:sns:us-east-1:652499160872:DP-Build --message-structure json --subject“ Test Build subject” --message“ {\\” default \\“: \\“ Foo \\”,\\“电子邮件\\”:\\“ Bar \\”}“

According to the docs there is a "Subject" key you can pass as a parameter: 根据文档,有一个“主题”键可以作为参数传递:

Blockquote 块引用

Subject The Subject parameter specified when the notification was published to the topic. 主题将通知发布到主题时指定的Subject参数。 Note that this is an optional parameter. 请注意,这是一个可选参数。 If no Subject was specified, then this name/value pair does not appear in this JSON document. 如果未指定主题,则此名称/值对不会出现在此JSON文档中。

Blockquote 块引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM