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

Function create

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

saveMethod · 0.95
TodoModelClass · 0.90
errorMethod · 0.80

Tested by

no test coverage detected