AWS(아마존클라우드)
[aws/lambda] 초간단 serverless api서버 만들기(lambda+APIGateway)
개발자 고포고
2022. 12. 1. 17:52
반응형
[aws/lambda] 초간단 serverless api서버 만들기(lambda+APIGateway)
#람다생성
#node안에서 자바스크립트 리턴값에 구현
#트리거를 api gateway로 등록
#new api / rest api / open 으로 선택
#하단에 나온 url로 접속하면 손쉽게 serverless로 api 서버를 만들 수 있다
#테스트 코드
let total = 0;
let gate1 = 0;
let gate2 = 0;
let gate3 = 0;
let gate4 = 0;
let gate5 = 0;
let gate6 = 0;
export const handler = async(event) => {
// TODO implement
const action = event.queryStringParameters.action;
const num = event.queryStringParameters.num;
//get
if(action == "0"){
}
//add
else if(action == "1")
{
switch(num) {
case "1":
gate1++;
break;
case "2":
gate2++;
break;
case "3":
gate3++;
break;
case "4":
gate4++;
break;
case "5":
gate5++;
break;
case "6":
gate6++;
break;
default:
break;
}
//clear
}
else if(action == "2")
{
switch(num) {
case "0":
total = 0;
gate1 = 0;
gate2 = 0;
gate3 = 0;
gate4 = 0;
gate5 = 0;
gate6 = 0;
break;
case "1":
total = total - gate1;
gate1=0;
break;
case "2":
total = total - gate2;
gate2=0;
break;
case "3":
total = total - gate3;
gate3=0;
break;
case "4":
total = total - gate4;
gate4=0;
break;
case "5":
total = total - gate5;
gate5=0;
break;
case "6":
total = total - gate6;
gate6=0;
break;
default:
break;
}
}
total = gate1+gate2+gate3+gate4+gate5+gate6;
const response = {
statusCode: 200,
body: JSON.stringify({num:num,action:action,gate1:gate1,gate2:gate2,gate3:gate3,gate4:gate4,gate5:gate5,gate6:gate6,total:total}),
};
return response;
};
#serverless #aws #node #lambda #api gateway
반응형