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
asked 2 years ago462 views
2 Answers
0
Accepted Answer

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
answered 2 years ago
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
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions