-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda_function.py
35 lines (31 loc) · 1.1 KB
/
lambda_function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import json
import boto3
import logging
import os
from botocore.exceptions import ClientError
logger = logging.getLogger()
s3_client = boto3.client('s3')
def lambda_handler(event, context):
return get_object(event)
def get_object(event):
queryParam = event["queryStringParameters"]
try:
key = queryParam["objectKey"] + '.json'
response = s3_client.generate_presigned_url('get_object',
Params={'Bucket': os.environ.get('BUCKETNAME'),
'Key': key},
ExpiresIn=3600)
except ClientError as e:
logging.error(e)
return None
# The response contains the presigned URL
return {
'statusCode': 200,
'headers': {
"Content-Type": 'application/json',
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": 'Content-Type,X-Amz-Date,X-Api-Key',
"Access-Control-Allow-Methods": "OPTIONS,POST"
},
'body': json.dumps(response)
}