import boto3
import json
import logging
logger = logging.getLogger()
logger.setLevel(logging.ERROR)
ses = boto3.client('ses')
def lambda_handler(event, context):
try:
# リクエストボディからdeviceidを取得
request_body = event['body']
device_id = json.loads(request_body)['deviceid']
# SESでメールを送信
# Source/送信元メール
# recipient_email/送信元メール
recipient_email = 'test@test.mail.com'
response = ses.send_email(
Source='your-email-address@example.com',
Destination={
'ToAddresses': [recipient_email]
},
Message={
'Subject': {
'Data': 'Test email'
},
'Body': {
'Text': {
'Data': f'This is a test email sent from AWS Lambda. Device ID: {device_id}'
}
}
}
)
return {
'statusCode': 200,
'body': json.dumps('Email sent successfully')
}
except Exception as e:
logger.error('Failed to send email: ' + str(e))
raise
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme