MCPcopy Create free account
hub / github.com/serverless/examples / create

Function create

aws-python-http-api-with-pynamodb/todos/create.py:8–30  ·  view source on GitHub ↗
(event, context)

Source from the content-addressed store, hash-verified

6
7
8def create(event, context):
9 print(event['body'])
10 data = json.loads(event['body'])
11 if 'text' not in data:
12 logging.error('Validation Failed')
13 return {'statusCode': 422,
14 'body': json.dumps({'error_message': 'Couldn\'t create the todo item.'})}
15
16 if not data['text']:
17 logging.error('Validation Failed - text was empty. %s', data)
18 return {'statusCode': 422,
19 'body': json.dumps({'error_message': 'Couldn\'t create the todo item. As text was empty.'})}
20
21 a_todo = TodoModel(todo_id=str(uuid.uuid1()),
22 text=data['text'],
23 checked=False)
24
25 # write the todo to the database
26 a_todo.save()
27
28 # create a response
29 return {'statusCode': 201,
30 'body': json.dumps(dict(a_todo))}
31

Callers

nothing calls this directly

Calls 3

saveMethod · 0.95
TodoModelClass · 0.90
errorMethod · 0.80

Tested by

no test coverage detected