0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AWS Lambdaからteamsへ送信してみる

Last updated at Posted at 2022-08-23

背景

  • 新プロジェクトに夜間のバッチ処理の開始の時に、teamsチャネルへ送信する
  • バッチ処理失敗の時も送信する

調査

webhookを作成

実装

import urllib3
import json
import datetime

http = urllib3.PoolManager()
DIFF_JST_FROM_UTC = 9

def lambda_handler(event, context):
    url = "xxx"
    
    now = datetime.datetime.utcnow() + datetime.timedelta(hours=DIFF_JST_FROM_UTC)
    theme_color_alert = "d700be"
    theme_color_normal = "0076D7"
    msg = {
            "@type": "MessageCard",
            "@context": "<http://schema.org/extensions",>
            "themeColor": theme_color_normal,
            "summary": "バッチ処理開始しました",
            "sections": [{
                "activityTitle": "バッチ処理定時実行",
                "activityImage": "http://xxx"
                "facts": [
                {
                    "name": "時間",
                    "value": now.strftime('%Y年%m月%d日 %H:%M:%S')
                }, {
                    "name": "メッセージ",
                    "value": "バッチ処理が開始になりました"
                }],
                "markdown": "true"
            }]
    }
    
    encoded_msg = json.dumps(msg).encode('utf-8')
    resp = http.request('POST',url, body=encoded_msg)

結果

スクリーンショット 2022-08-23 15.38.38.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?