Last active
September 15, 2021 04:26
-
-
Save parth-trambadiya/0108b3522f628e2623db8092af072f9f 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 logging | |
import base64 | |
import boto3 | |
import os | |
logger = logging.getLogger() | |
logger.setLevel(logging.INFO) | |
s3_client = boto3.client('s3') | |
response = { | |
'statusCode': 200, | |
'headers': { | |
'Access-Control-Allow-Origin': '*', | |
'Access-Control-Allow-Credentials': 'true' | |
}, | |
'body': '' | |
} | |
def lambda_handler(event, context): | |
file_name = event['headers']['file-name'] | |
file_content = base64.b64decode(event['body']) | |
BUCKET_NAME = os.environ['BUCKET_NAME'] | |
try: | |
s3_response = s3_client.put_object(Bucket=BUCKET_NAME, Key=file_name, Body=file_content) | |
logger.info('S3 Response: {}'.format(s3_response)) | |
response['body'] = 'Your file has been uploaded' | |
return response | |
except Exception as e: | |
raise IOError(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment