Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@kazu_kazu

Lambdaでメッセージを編集してSNS Publishする一例

Lambdaのコード

 ヒアドキュメントと変数、json.dumpsを利用した一例です。
 SecurityHubの通知を例にして作成しています。

lambda_function
from __future__ import print_function
import json
import boto3
import os

sns = boto3.client("sns")
def lambda_handler(event, context):
    message = event["detail"]["findings"][0]
    msg = """
    Security Hubにより検知した違反内容
    セキュリティ基準コントロール:{standards_control_arn}
    タイトル:{title}
    説明:{description}
    セキュリティステータス:{status}
    重要度:{severity}
    修復手順:{remediation_text}({remedeation_url})

    対象リソース
    {resources}

    詳細
    --
    {detail}
    """.format(standards_control_arn=message["ProductFields"]["StandardsControlArn"], \
    title=message["Title"],\
    description=message["Description"], \
    status=message["Compliance"]["Status"], \
    severity=message["Severity"]["Label"],\
    remediation_text=message["Remediation"]["Recommendation"]["Text"], \
    remedeation_url=message["Remediation"]["Recommendation"]["Url"],\
    resources=json.dumps(message["Resources"], indent=4), \
    detail=json.dumps(event, indent=4))

    response = sns.publish(
        TopicArn=os.environ.get("sns_arn"),
        Subject="テスト",
        Message=msg
    )
    return response
0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
kazu_kazu
AWSが好きです。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?