Last active
December 12, 2018 02:29
-
-
Save shiro01/32a2a8cc6aacac95be6aacf9333de805 to your computer and use it in GitHub Desktop.
AWS SNSを使用したLambda関数からのメール送信
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 事前にAWSコンソールでAWSSNSのトピック、サブスクリプションを作成しておく | |
# ロールアタッチポリシー:AmazonSNSFullAccess | |
import boto3 | |
def lambda_handler(event, context): | |
sns_client = boto3.client('sns') | |
# トピックARNを指定する | |
topicarn = 'arn:aws:sns:ap-northeast-1:xxxxxxxxxxxx:test-send-email' | |
sns_client.publish( | |
TopicArn=topicarn, | |
Subject='Lambdaテストメール送信', | |
Message='This is test message via endpoint!', | |
) | |
return "end" | |
# メモ | |
# def sende_email_with_sns(topicarn, subject, message): | |
# try: | |
# sns_client = boto3.client('sns') | |
# sns_client.publish( | |
# TopicArn = topicarn, | |
# Subject = subject, | |
# Message = message, | |
# ) | |
# except Exception as e: | |
# print('Error: メール通知失敗', e) | |
# return e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment