MCPcopy Create free account
hub / github.com/aws-samples/aws-cdk-examples / handler

Function handler

python/serverless-backend/lambda-handler/index.py:37–64  ·  view source on GitHub ↗
(event, context)

Source from the content-addressed store, hash-verified

35
36
37def handler(event, context):
38 print(event)
39 # Generate random image id
40 image_id = str(uuid.uuid4())
41
42 data = json.loads(event['body'])
43 userid = data['userid']
44 img = base64.b64decode(data['photo'])
45
46 if upload_image(image_id, img, userid):
47 return {
48 'statusCode': 200,
49 'headers': {
50 'Access-Control-Allow-Headers': '*',
51 'Access-Control-Allow-Origin': '*',
52 'Access-Control-Allow-Methods': 'OPTIONS,POST,GET'
53 },
54 'body': json.dumps('Success!')
55 }
56 return {
57 'statusCode': 500,
58 'headers': {
59 'Access-Control-Allow-Headers': '*',
60 'Access-Control-Allow-Origin': '*',
61 'Access-Control-Allow-Methods': 'OPTIONS,POST,GET'
62 },
63 'body': json.dumps('Request Failed!')
64 }

Callers

nothing calls this directly

Calls 1

upload_imageFunction · 0.85

Tested by

no test coverage detected