Skip to content

Instantly share code, notes, and snippets.

@selcukcihan
Last active December 19, 2019 14:31
Show Gist options
  • Save selcukcihan/340d6a90dd53b227fd96e7e2c465a861 to your computer and use it in GitHub Desktop.
Save selcukcihan/340d6a90dd53b227fd96e7e2c465a861 to your computer and use it in GitHub Desktop.
Mail gondermek icin lambda
import boto3
import json
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
s3 = boto3.resource('s3')
ses = boto3.client('ses')
def lambda_handler(event, context):
for record in event['Records']:
bucket = record['s3']['bucket']['name']
key = record['s3']['object']['key']
logger.info("%s bucket'ındaki %s objesi işleniyor.", bucket, key)
s3_object = s3.Object(bucket, key).get()
transcribe_response = json.loads(s3_object['Body'].read().decode("utf-8"))
text = transcribe_response["results"]["transcripts"][0]["transcript"]
logger.info("Email içeriği: %s", text)
response = ses.send_email(
Source='[email protected]',
Destination={
'ToAddresses': [
'[email protected]',
]
},
Message={
'Subject': {
'Data': 'Sesten yazıya dönüşüm',
'Charset': 'UTF-8'
},
'Body': {
'Text': {
'Data': text,
'Charset': 'UTF-8'
}
}
}
)
logging.info("Email id'si: %s", response["MessageId"])
return {
'statusCode': 200,
'body': json.dumps('Email başarıyla gönderildi.')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment