Skip to content

Instantly share code, notes, and snippets.

@koorukuroo
Created April 21, 2026 02:50
Show Gist options
  • Select an option

  • Save koorukuroo/7b8a6ce0bf5affd1b1ae08827b3e4ad8 to your computer and use it in GitHub Desktop.

Select an option

Save koorukuroo/7b8a6ce0bf5affd1b1ae08827b3e4ad8 to your computer and use it in GitHub Desktop.
import json, uuid, datetime
# In-memory store (DynamoDB로 교체 예정)
store = {}
def lambda_handler(event, context):
method = event['httpMethod']
path_params = event.get('pathParameters') or {}
query_params = event.get('queryStringParameters') or {}
if method == 'POST': # 생성: body
body = json.loads(event.get('body', '{}'))
item_id = str(uuid.uuid4())[:8]
item = {"id": item_id, **body, "status": "open",
"createdAt": datetime.datetime.now().isoformat()}
store[item_id] = item
return response(201, item)
elif method == 'GET' and path_params.get('id'):
item = store.get(path_params['id']) # 단건 조회: path
return response(200, item) if item else response(404, {"error": "Not found"})
elif method == 'GET': # 목록 조회: query
status = query_params.get('status', 'all')
items = [v for v in store.values()
if status == 'all' or v.get('status') == status]
return response(200, {"items": items, "total": len(items)})
elif method == 'PUT': # 수정: path + body
item_id = path_params['id']
body = json.loads(event.get('body', '{}'))
if item_id not in store: return response(404, {"error": "Not found"})
store[item_id] = {**store[item_id], **body}
return response(200, store[item_id])
elif method == 'DELETE': # 삭제: path
item_id = path_params['id']
if item_id not in store: return response(404, {"error": "Not found"})
del store[item_id]
return response(204, None)
def response(code, body):
return {"statusCode": code, "headers": {"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"},
"body": json.dumps(body, ensure_ascii=False) if body else ""}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment