Created
February 22, 2018 19:18
-
-
Save elliotforbes/2fc27aebc9441ce101eaabe816ce70ad to your computer and use it in GitHub Desktop.
This file contains 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 json | |
import boto3 | |
from decimal import Decimal as D | |
dynamodb = boto3.resource('dynamodb', region_name="eu-west-1") | |
s3 = boto3.client('s3') | |
class DecimalEncoder(json.JSONEncoder): | |
def default(self, obj): | |
if isinstance(obj, D): | |
return float(obj) | |
return json.JSONEncoder.default(self, obj) | |
def list(event, context): | |
keys = [] | |
resp = s3.list_objects_v2(Bucket='imgur-serverless') | |
for obj in resp['Contents']: | |
keys.append(obj['Key']) | |
response = { | |
"statusCode": 200, | |
"body": json.dumps(keys, cls=DecimalEncoder), | |
'headers': { | |
'Content-Type': 'application/json', | |
'Access-Control-Allow-Origin': '*' | |
}, | |
} | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment