Skip to content

Instantly share code, notes, and snippets.

@elliotforbes
Created February 22, 2018 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliotforbes/2fc27aebc9441ce101eaabe816ce70ad to your computer and use it in GitHub Desktop.
Save elliotforbes/2fc27aebc9441ce101eaabe816ce70ad to your computer and use it in GitHub Desktop.
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