Created
September 4, 2020 14:05
-
-
Save ljmocic/0fcda622bffb57806aac99e1f250eaa2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import boto3 | |
import email | |
import json | |
from pprint import pprint | |
from base64 import b64decode | |
s3 = boto3.client('s3') | |
BUCKET_NAME = '' | |
def lambda_handler(event, context): | |
message = json.loads(event['Records'][0]['Sns']['Message']) | |
decoded_message = b64decode(message['content']).decode('utf-8') | |
email_obj = email.message_from_string(decoded_message) | |
for part in email_obj.walk(): | |
content_type = part.get_content_type() | |
if 'sheet' in content_type: | |
try: | |
s3.put_object(Body=b64decode(part.get_payload()), Bucket=BUCKET_NAME, Key="latest-attachment.xslx") | |
except: | |
continue | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment