ボタンを押すとFunk経由でAWS Lambdaを呼び出してみる
From __future__ import print_function import boto3 import os import json import logging import dateutil.parser from datetime import datetime, timedelta import xml.etree.ElementTree as ET import urllib.request logger = logging.getLogger() logger.setLevel(logging.INFO) ses = boto3.client('ses') from_address = "送信元のメールアドレス" to_address = [] to_address.append("送信先メールアドレス") def lambda_handler(event, context): clickType = event["clickTypeName"] batteryLevel = event["batteryLevel"] lat = context.client_context.custom["location"]["lat"] lon = context.client_context.custom["location"]["lon"] imsi = context.client_context.custom['imsi'] apiUrl = 'https://map.yahooapis.jp/geoapi/V1/reverseGeoCoder?lat=' + str(lat) + '&lon=' + str(lon) + '&appid=' + os.environ['yahooMapApi'] response = urllib.request.Request(apiUrl) with urllib.request.urlopen(response) as res: data = res.read() root = ET.fromstring(data) titl = root[1][0][1].text mapUrl = 'http://maps.google.co.jp/maps?q=' + str(lat) + ',' + str(lon) body = "\n" + titl + " にいます\n" + mapUrl ts = datetime.now() + timedelta(hours=9) ts = ts.strftime('%Y/%m/%d %H:%M:%S') if (clickType == 'SINGLE'): subject = 'SINGLE' body = str(ts) + body elif (clickType == 'DOUBLE'): subject = 'DOUBLE' body = str(ts) + body elif (clickType == 'LONG'): subject = 'LONG' body = str(ts) + body else: subject = 'failed' body = 'failed' ses.send_email(Source=from_address, Destination={'ToAddresses': to_address}, Message={'Subject': {'Data': subject}, 'Body': {'Text': {'Data': body}}})