티스토리 뷰
반응형
[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
반응형
'AWS(아마존클라우드)' 카테고리의 다른 글
[nginx/log] nginx 로그 위치 및 로그 분석하기(특정 URL 접속횟수) (0) | 2024.04.23 |
---|---|
linux(amazonlinux1)에서 ftp로 파일 보내기(도커포함) (0) | 2024.01.25 |
[aws/linux] mysql 도커로 설치 및 테스트 (0) | 2023.12.11 |
[aws/alb]Application Load Balancer를 활용한 https 구현 및 개념 이해(완전 종결!) (0) | 2022.07.16 |
[AWS/Lambda] 테스트에서 Input Parameter 추가 및 객체정보 가져오기 (0) | 2022.07.12 |
댓글
반응형