AWS Lambda HTTP POST request


I am trying to make HTTP POST requests to AWS Lambda with BearSSLClient on Arduino Nano 33 IoT, but the endpoint always disconnects after 60 seconds. I verified it with curl requests from the host and it responds just fine.

I generated the certificates, created the AWS Thing and created a HTTP Endpoint. Maybe I should not be using SSL/TLS?

The code looks like this:

WiFiSSLClient    wifiClient;            // Used for the TCP socket connection
BearSSLClient client(wifiClient); // Used for SSL/TLS connection, integrates with ECC508

void setup() {
  //Initialize serial and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);

  String fv = WiFi.firmwareVersion();
    Serial.println("Please upgrade the firmware");
   if (!ECCX08.begin()) {
    Serial.println("No ECCX08 present!");
    while (1);

  // Set a callback to get the current time
  // used to validate the servers certificate

  // Note how the certificate is formed
  String(certificate) = String(client_cert) + String(root_ca);
  // Set the ECCX08 slot to use for the private key
  // and the accompanying public certificate for it
  client.setEccSlot(0, certificate.c_str());

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
  Serial.println("Connected to WiFi");

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  if (client.connect(server, 443)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET / HTTP/1.1");
    client.print("Host: ");
    //client.print("content-length: ");
    //lambda.println("connection: close");


void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()) {
    char c =;

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println("disconnecting from server.");

    // do nothing forevermore:
    while (true);

Rather than just spinning after the client.stop() have you tried to reconnect using client.connect?

Have you tried to set the timeout using setConnectionTimeout(milis)? I believe the default is 1000 so about 1 second, this might affect how long the client waits before deciding it is disconnect - I'm not entirely sure :roll_eyes: but worth trying as an experiment as it may help.

1 Like

I am really baffled by what AWS expects from me in this case. On the host I understand that the TLS handshake lasts very briefly and I have no idea how long it takes in the case of BearSSL implementation of it.

Currently, I decided to communicate through MQTT and it works like a charm (well almost - my payload is getting truncated somehow - 1600 bytes), and I relay my publish requests to AWS Lambda.

I will try applying what you said nevertheless.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.