CodePipeline activity notification JSON ends up malformed at Microsoft Teams

0

Has anybody else tried to send CodePipeline events over to a Microsoft Teams channel using the following examples

https://aws.amazon.com/premiumsupport/knowledge-center/sns-lambda-webhooks-chime-slack-teams/

and end up with the displayed JSON having no value for the additionalAttributes property? It is supposed to be an empty {} object.

{
"account": "ACCOUNTNUMBER",
"detailType": "CodePipeline Pipeline Execution State Change",
"region": "REGION",
"source": "aws.codepipeline",
"time": "2022-01-17T08:59:36Z",
"notificationRuleArn": "RULEARN",
"detail": {
"pipeline": "PIPELINE",
"execution-id": "GUID",
"execution-trigger": {
"trigger-type": "Webhook",
"trigger-detail": "CODESTARARN"
},
"state": "STARTED",
"version": 1.0
},
"resources": [
"PIPELINEARN"
],
"additionalAttributes": 
}

I logged down the Python formatting statements and the resultant encoded string does include the {} so I guess somehow the Teams side does not like empty objects and drops it off?

icelava
已提问 2 年前467 查看次数
2 回答
0
已接受的回答

We are sending to Microsoft Teams that payload format.

{ "text": "STRINGYFIED_JSON" }

Where STRINGYFIED_JSON = the serialised SNS message object.

I tested further by adding a placeholder property to the blank object for additionalAttributes and Teams did accept that and rendered proper JSON in the post.

# Add placeholder property to potentially empty object {} in additionalAttributes
# Microsoft Teams may not like it and not render in rendered post text.
snsMessage['additionalAttributes']['placeholder'] = "Prevent empty object."
icelava
已回答 2 年前
0

As described in the Knowledge Center Article, the minimum payload for TEAMS has to be:

{"text": "Some Text"}

Just {} won't work.

The article simply uses the JSON payload of the SNS message and forwards it to the TEAMS Webhook, however they support Adaptive Cards and their legacy format Actionable Message which allows you to format your information quite nicely. Our team uses the Python module pyadaptivecards to make the layout of our cards easier.

wolfadr
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则