본문 바로가기

아두이노에서 AWS Lambda Restful API를 인증키와 함께 POST 로 호출하는 예제 코드입니다.

(The way how to call AWS Lambda Restful API from Arduino by HTTP POST Method)


#include <WiFiClientSecure.h>

  const int httpPort = 443; //for https
  const char* host = "abcdefghijklmn.execute-api.ap-????-1.amazonaws.com";

void requestCall() {
  WiFiClientSecure client;

  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }

  String url = "/prod/my/resource"; //resource path

  // post data
  String jsonbody = String("{\r\n \"param1\" : \"1234\",\r\n  \"param2\" : \"1234\"\r\n}";

  // This will send the request to the server
  String requestBody = String("POST ") + url + " HTTP/1.1\r\n" +
             "Host: " + host + "\r\n" +
             "api-key: abcdefffdefffff88881112343434\r\n" +
             "Content-Type: application/json\r\n" +
             "Cache-Control: no-cache\r\n" +
             "Content-length: " + String(jsonbody.length()) + "\r\n\r\n" +
             jsonbody;

  client.print(requestBody); 
 
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client.stop();
      return;
    }
  }
  
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
}


건투를 빕니다!







번호 제목 날짜 조회 수
공지 [TIP] 자작 운영체제 AiRPOS 소스를 공개합니다. 2026.07.04 11281
공지 [TIP] PYTHON 에서 "UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 6987: illegal multibyte sequence" 오류 날때... [52] 2016.02.20 264647
공지 [펌] ARM GCC Inline Assembler Cookbook 2006.08.18 56612
공지 [TIP] R에서 페이스북 페이지 정보 크롤링 하기 [6] 2017.02.11 38663
150 [TIP] 파이선에서 AWS Lambda로 만든 Restful API 호출하기 (How to call AWS Lambda Restful API from Python) 2018.01.23 2734
149 [TIP] 파이선에서 서브프로세스를 실행시키고 출력되는 내용을 얻어오기 2018.01.22 12616
» [TIP] 아두이노에서 AWS Lambda로 제작한 Restful API 호출하기 (The way how to call AWS Lambda Restful API from Arduino) 2018.01.18 2417
147 [TIP] 파이선에서 Redis 이벤트 받기 2017.10.12 1967
146 [TIP] 파이선에서 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position ... 오류 해결 방법 2017.09.29 3350
145 [TIP] The function size must be used with a prefix when a default namespace is not specified 오류 해결하기 2017.08.02 4308
144 [TIP] 페이스북 개인 담벼락의 좋아요수 크롤링하기 2017.07.15 2479
143 [TIP] 자바스크립트와 PHP코드간에 암호화 통신하기 (Encrypt with Javascript, Decrypt with PHP) [2] 2017.03.16 6090
142 [TIP] GUNMAN의 영화 점수 테이블을 이용한 딥러닝 예제 2017.02.15 3150
141 [TIP] R에서 페이스북 페이지 정보 크롤링 하기 [6] 2017.02.11 38663
140 [TIP] 네이버 영화 정보와 전문가 평점 얻어오기 2017.02.10 8643
139 [TIP] 네이버 오픈 API를 로컬 PC에서 호출하기 2017.02.01 4366
138 [TIP] php로 기상청에서 제공하는 기상정보 API 호출하기 2017.01.17 10660
137 [TIP] node 에서 Basic authentication 인증과 함께 http, https 요청하기 2016.09.01 2626
136 [TIP] node의 lambda-local 테스트 팁 2016.08.19 1870
135 [TIP] 데이터를 Node에서 암호화하고 PHP에서 복호화 하기 2016.08.19 2028
134 [TIP] Docker상의 Syntaxnet 결과 포맷을 수정하기 2016.08.07 3048
133 [TIP] SyntaxNet을 Windows에서 실행하기 [1] 2016.05.25 2001
132 [TIP] TensorFlow를 윈도우에서 사용하기 (A way to use TensorFlow on Windows) [3] 2016.04.16 23437
131 [TIP] 파이선으로 TED에서 가장많이 사용된 단어들 줄세우기 2016.04.03 2609