Connecting ESP32 to Amazon Web Services - AWS IoT Core

Welcome to our new blogpost about testing the IoT Core service of the most famous cloud provider, Amazon!

At ThingForward, we are exploring different cloud providers' varied functions for IoT applications. Until today, we have examined the usage and features of Microsoft Azure Part 1 , Part 2 and Google IoT Core .

Today we will zoom into Amazon IoT Core. Amazon is leading the cloud market for more than 10 years now, thanks to its enterprise-ready solutions and powerful database services. It is not surprising that the IoT services of these cloud providers are relatively new, so don't forget that they are still being improved.

By following this blogpost, you will be able to connect your ESP32 MCU to the cloud, send and receive messages by using HTTPS/MQTT protocols.

For today, you will need:

  • Amazon AWS Account


Image 1

Part 1: Connecting the Local Computer to the Cloud

  • Register for an AWS account and choose the free plan.

  • Open AWS-IoT or click on this link.

Image 2

  • Select your region and language on black bars.

Image 3

  • Navigate to Manage>Things and Register a Thing>Create a Single Thing

Image 4

  • Enter your credentials and proceed.

  • Select "Create Certificate".

Image 5

  • Don't forget to click on Activate! Download the following certificates and click done.
  1. aws-root-ca.pem
  2. certificate.pem.crt
  3. private.pem.key

Image 6

  • Open AWS IoT interface and on the left pane find Secure>Policies and select "Create a Policy".

Image 7

  • Open Secure>Certificates, click on ... and select "Attach Policy". Select the policy and attach it.

Image 8

  • Open Manage on the left pane and open the thing.

Image 9

  • Click on Interact to see your host address, the first link. Now click on "Connect a Device".

Image 10

  • Choose OS and machine and proceed.

Image 11

  • Download the SDK and follow the steps and see the messages on the screen.

Image 12

After all these steps, this is what the console output should look like:

Received a new message:

b'{"message": "Hello World!", "sequence": 0}'

from topic:



Image 13

Part 2: Connecting the ESP32 to the Cloud

Now, let's connect our node to the AWS. To do so:

  • Please download the AWS library from

  • In order to use it, replace it under your Arduino workspace. AWS_IOT file should be placed under /home/Arduino/libraries

  • Open the pubSubTest.ino and give your credentials as:
char WIFI_SSID[]="SSID Name";


char HOST_ADDRESS[]="";

char CLIENT_ID[]= "Policy Name";

char TOPIC_NAME[]= "Thing Name";

Remember: To find your host address, click on the Manage > Things, click on the thing and Interact. (10th Image). The first link is your host address.

In an earlier step, you downloaded three certificates. Under AWS_IOT file, open aws_iot_certificates.c and copy/paste your certificate credentials.

To open the downloaded certificates:

$ cd path/to/certificates
$ cat xxyy-private.pem.key

Image 14

Certificate format under aws_iot_certificates.c should be in this form:

const char aws_root_ca_pem[] = "-----BEGIN CERTIFICATE-----\n"
"-----END CERTIFICATE-----";

Now you can upload the code and open serial monitor. You will see the following results:

Image 15


That's it! You're on the cloud!

AWS IoT Core is a perfect orientation tool for exploring IoT Services on Amazon. Finding out more from AWS is the key of increasing the efficiency and usability of your IoT project, like other services in order to sketch real-time data from the sensors or invoking the methods.

This concludes our blogpost about Amazon Web Services. Stay tuned for more upcoming blogposts about cloud services!


Follow ThingForward on Twitter, Facebook and Linkedin!