Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AWS Lambda と API GatewayでRails使わずに済んだ話

ryonext
November 19, 2015

AWS Lambda と API GatewayでRails使わずに済んだ話

ryonext

November 19, 2015
Tweet

More Decks by ryonext

Other Decks in Technology

Transcript

  1. 2 import boto3 3 import json 4 5 OUR_EMAIL =

    "ӡӦαΠυͷϝʔϧΞυϨε" 6 7 def send_email(to, reply, subject, body): 8 client = boto3.client('ses', region_name='us-east-1') 9 10 response = client.send_email( 11 Source=OUR_EMAIL, 12 Destination={ 13 'ToAddresses': [ 14 to, 15 ] 16 }, 17 Message={ 18 'Subject': { 19 'Data': subject, 20 }, 21 'Body': { 22 'Text': { 23 'Data': body, 24 }, 25 } 26 }, 27 ReplyToAddresses=[ 28 reply, 29 ], 30 ReturnPath=OUR_EMAIL 31 ) 32 33 def send_inquiry_mail(email, message): 34 send_email(OUR_EMAIL, email, "໰͍߹Θ໊ͤ݅", message) 35 36 def send_auto_reply_mail(name, email): 37 message = "ࣗಈฦ৴" 38 send_email(email, OUR_EMAIL, "ࣗಈฦ৴໊݅", message) 39 40 def lambda_handler(event, context): 41 email = event["email"] 42 message = event["message"] 43 send_inquiry_mail(email, message) 44 send_auto_reply_mail(email)
  2. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [

    "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": "arn:aws:logs:*:*:*" }, { "Effect": "Allow", "Action": [ "ses:*" ], "Resource": "*" } ] }
  3. 4FDVSJUZ w "84*". w 0QFO w 0QFOXJUIBDDFTTLFZ w ͕͋Δɻ*".͸ಛఆͷΠϯελϯε͔Βݺ͹ΕΔ༻్ͷ "1*ʹ࢖͏΋ͷͩΖ͏ɻ0QFOXJUIBDDFTTLFZ͸ɺΩʔ

    ΛຒΊࠐΜͩಛఆͷΫϥΠΞϯτ͔Βݺ͹ΕΔ΋ͷͳͷ ͰεϚϗΫϥΠΞϯτΞϓϦʹ࢖͏΋ͷͩͱࢥΘΕΔɻ