AWS STUDY
PuTTY로 aws ec2로 만든 리눅스 환경 접속하기
ec2에-npm-설치
express설치하고 helloworld 출력하기 feat 포트 열기
AWS, Angular를 이용한 todo-list 만들기(1)
AWS, Angular를 이용한 todo-list 만들기(2)
AWS, Angular를 이용한 todo-list 만들기(2)
메서드 추가 생성
API Gateway에서 /
선택 후 작업
-메서드 생성
GET
선택 후 myTodos
함수 선택
PATCH
와 POST
만들고 myTodos
선택
![image](https://user-images.githubusercontent.com/48123604/60394461-b60cc780-9b5f-11e9-9415-76814f52eb1a.png)
매칭 템플릿 생성
application/json
, 메소드 요청 패스스루
로 GET
, PATCH
, POST
에 각각 추가
요청에 따라 다른 응답 만들기
요청 구분
path”: {
“id”: “2”
} 처럼 path에 id가 있으면 해당 id에 대한 요청
path가 비어 있으면 todos에 대한 요청
Lambda 코드 수정
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 48 49 50
| const routeMap = { "/": { GET: () => { const result = "전체 todos"; return result; }, PATCH: event => { const modifyALL = event["body-json"]; const result = { modifyALL }; return result; }, POST: event => { const add = event["body-json"]; const result = { add }; return result; } }, "/{id}": { PATCH: event => { const modify = event["body-json"]; const target = event.params.path.id; const result = { target, modify }; return result; }, DELETE: event => { const target = event.params.path.id; const result = { target }; return result; } } };
function router(event) { const method = routeMap[event.context["resource-path"]][event.context["http-method"]]; if (method) return method(event); else return { body: { Error: "Invalid Path" } }; }
exports.handler = async event => { const response = router(event); return response; };
|
각 메서드에 따른 실제 DB구현은 다음에