aws-angular-todolist-2

AWS STUDY

  1. PuTTY로 aws ec2로 만든 리눅스 환경 접속하기

  2. ec2에-npm-설치

  3. express설치하고 helloworld 출력하기 feat 포트 열기

  4. AWS, Angular를 이용한 todo-list 만들기(1)

  5. AWS, Angular를 이용한 todo-list 만들기(2)


AWS, Angular를 이용한 todo-list 만들기(2)

메서드 추가 생성

API Gateway에서 /선택 후 작업-메서드 생성

GET선택 후 myTodos 함수 선택

PATCHPOST 만들고 myTodos 선택

image

매칭 템플릿 생성

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 => {
// TODO implement
// const response = {
// httpMethod : event.context["http-method"],
// resourcePath : event.context["resource-path"],
// path : event.params.path,
// body : event["body-json"]
// };
const response = router(event);
return response;
};

각 메서드에 따른 실제 DB구현은 다음에

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×