Repository navigation
Expand file tree
/
Copy pathlambda_post.py
More file actions
47 lines (40 loc) · 1.62 KB
/
Copy pathlambda_post.py
File metadata and controls
47 lines (40 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import json
import boto3
from decimal import Decimal
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.Table('DisneyAcceleratorTracker')
def lambda_handler(event, context):
try:
body = json.loads(event['body'])
required = ['companyId', 'name', 'cohortYear', 'techCategory',
'productionStage', 'disneyVertical', 'technologyMaturity']
for field in required:
if field not in body:
return {
'statusCode': 400,
'headers': {'Access-Control-Allow-Origin': '*'},
'body': json.dumps({'error': f'Missing field: {field}'})
}
item = {
'companyId': body['companyId'],
'name': body['name'],
'cohortYear': int(body['cohortYear']),
'techCategory': body['techCategory'],
'productionStage': body['productionStage'],
'disneyVertical': body['disneyVertical'],
'technologyMaturity': body['technologyMaturity'],
'status': body.get('status', 'active cohort'),
'notes': body.get('notes', '')
}
table.put_item(Item=item)
return {
'statusCode': 200,
'headers': {'Access-Control-Allow-Origin': '*'},
'body': json.dumps({'message': 'Company added successfully', 'company': item})
}
except Exception as e:
return {
'statusCode': 500,
'headers': {'Access-Control-Allow-Origin': '*'},
'body': json.dumps({'error': str(e)})
}