일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- dynamodb
- 펌웨어
- 전기차충전
- raspberry
- 보안
- STM32
- esp8266
- 플라스크
- 디자인패턴
- IOT Core
- 서버리스
- 충전기
- Android
- 홈어시스턴트
- homeassistant
- everon
- 안드로이드
- 라즈베리파이
- flask
- thread
- AWS
- 완속충전기
- 전기차충전기
- OCPP
- 급속충전기
- 파이썬
- lambda
- YMODEM
- 전기차
- 에버온
Archives
- Today
- Total
Louie NRT Story
[AWS] API Gateway -> Lambda 본문
반응형
Writed: 27 JAN 2020
Index
1. Make Lambda Function
2. Create API Gateway
3. Test an API's invoke url
1. Make Lambda Function
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
51
52
53
54
55
56
|
'use strict';
console.log('Loading hello world function');
exports.handler = async (event) => {
let name = "you";
let city = 'World';
let time = 'day';
let day = '';
let responseCode = 200;
console.log("request: " + JSON.stringify(event));
if (event.queryStringParameters && event.queryStringParameters.name) {
console.log("Received name: " + event.queryStringParameters.name);
name = event.queryStringParameters.name;
}
}
if (event.headers && event.headers['day']) {
}
if (event.body) {
if (body.time)
time = body.time;
}
let greeting = `Good ${time}, ${name} of ${city}.`;
if (day) greeting += ` Happy ${day}!`;
let responseBody = {
message: greeting,
input: event
};
// The output from a Lambda proxy integration must be
// in the following JSON object. The 'headers' property
// is for custom response headers in addition to standard
// ones. The 'body' property must be a JSON string. For
// base64-encoded payload, you must also set the 'isBase64Encoded'
// property to 'true'.
let response = {
statusCode: responseCode,
headers: {
"x-custom-header" : "my custom header value"
},
body: JSON.stringify(responseBody)
};
console.log("response: " + JSON.stringify(response))
return response;
};
|
2. Create API Gateway
1) Create an empty API
2) Create Resource
3) Create method
4) Deploy API
5) Note API's invoke API
3. Test an API with cURL
1) Download cURL from http://curl.haxx.se/windows
2) Execute curl.exe with Options(Below URL is exmaple)
.\curl.exe -v -X POST "https://r275xc9bmd.execute-api.us-east-1.amazonaws.com/test/helloworld?name=John&city=Seattle" -H "content-type: application/json" -H "day: Thursday"
Reference:
반응형
'서버시스템' 카테고리의 다른 글
[AWS] IoT Core -> Lambda -> DynamoDB (2) (0) | 2020.02.04 |
---|---|
[AWS] IoT Core -> Lambda -> DynamoDB (1) (0) | 2020.01.27 |
[AWS] IOT Core Lambda (0) | 2020.01.13 |
[AWS] IOT Core DynamoDB (0) | 2020.01.13 |
[AWS] IOT Core SNS 규칙 (0) | 2020.01.11 |
Comments