# AWS IoT Core

[AWS IoT Core](https://aws.amazon.com/iot-core/) is a managed cloud service that allows connected devices to interact easily and securely with cloud applications and other devices. The integration with AWS IoT Core is facilitated through [Device Shadow](https://docs.aws.amazon.com/iot/latest/developerguide/iot-device-shadows.html).

* **Uplink Support**: Blynk supports uplinks through Device Shadow updates, allowing seamless data communication.
* **Downlink Support**: Downlinks are managed by updating the shadow's desired state, ensuring synchronized device operation.
* **Device Importing**: Efficiently import devices, simplifying asset management.

### Connecting the integration

To connect the AWS IoT Core integration, you need to complete several fields and actions in AWS to enable Blynk to connect to your AWS IoT Core server and access your devices.

First, open your **Blynk Console** and go to **Developer Zone** → **Integrations** → **AWS IoT Core Integration**.

<figure><img src="https://1839001309-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBFTVMf7L6S67HOuqVC%2Fuploads%2FpCkVYfTRPCRWRVpvci4A%2FAWS%20integration%20page.png?alt=media&#x26;token=2ebcdf77-d91c-4dad-8963-da19d1d31173" alt=""><figcaption></figcaption></figure>

Fill in all the required fields:

#### **1. Region**

Begin by selecting your AWS Region. You can locate this in the top-right corner of the AWS Management Console, near your account name.

#### **2. AWS IoT Core Domain**

Provide the AWS IoT Core Domain. To find it:

* Navigate to **AWS IoT Core** in the AWS Console.
* Go to **Connect** → **Domain Configurations** and copy the domain name.

<figure><img src="https://1839001309-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBFTVMf7L6S67HOuqVC%2Fuploads%2F9393NANxr0FXPhzBWh3b%2FAWS%20domain%20configuration.png?alt=media&#x26;token=3b7f9614-32e5-4407-a497-6e8c680eade8" alt=""><figcaption></figcaption></figure>

#### **3. AWS IoT Credentials Provider Domain**

If you have the AWS CLI tool installed and authorized to your account, execute the following command to retrieve the Credentials Provider Domain:

```bash
aws iot describe-endpoint --endpoint-type iot:CredentialProvider
```

Alternatively, you can run this command in the AWS Console using the CloudShell tool.

#### **4. AWS Account ID**

Find your AWS Account ID by clicking on your account name (top-right corner) in the AWS Console and copying the **Account ID** displayed.

#### **5. Create a Policy for Blynk Connection**

1. Copy the Policy JSON provided on Blynk's integration page.
2. In the AWS Console, go to **AWS IoT Core** → **Security** → **Policies** → **Create New**.
3. Assign a name to the policy (e.g., `BlynkPolicy`).
4. Select the **JSON Policy Editor**, paste the copied JSON policy, and click **Create**.

<figure><img src="https://1839001309-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBFTVMf7L6S67HOuqVC%2Fuploads%2FkHn6ZdODsIMCcXnkuWBd%2FAWS%20policy%20creation.png?alt=media&#x26;token=f4698486-718a-413f-adbd-9d5f1e34ef97" alt=""><figcaption></figcaption></figure>

#### **6. Create Certificates for the Blynk Connection**

1. In the AWS Console, navigate to **AWS IoT Core** → **Security** → **Certificates**.
2. Click **Add certificate** → **Create certificate**.
3. Change its status to **Active** and click **Create**.
4. Download the **Device Certificate** and **Private Key** files, then upload them to the corresponding section on the Blynk integration page.<br>

   <figure><img src="https://1839001309-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBFTVMf7L6S67HOuqVC%2Fuploads%2FEjKMUAHiDQZNXa48iRb6%2FAWS%20certificate%20download%20screen.png?alt=media&#x26;token=d7cb6ae8-960a-40ee-9754-d22f9877ae18" alt="" width="309"><figcaption></figcaption></figure>
5. Click **Continue** in the Blynk interface.
6. In the AWS Console, open the newly created certificate.
7. Click **Attach policies**, select the previously created policy (e.g., `BlynkPolicy`), and click **Attach policies**.

<figure><img src="https://1839001309-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBFTVMf7L6S67HOuqVC%2Fuploads%2FN6gXSKY8OySnqhSW2Pjz%2FAWS%20attach%20certificate%20policy%20screen.png?alt=media&#x26;token=c79cac79-f079-4055-8d46-f32411a0f234" alt=""><figcaption></figcaption></figure>

#### **7. Create a Blynk Role**

1. On the Blynk integration page, copy the **Role JSON**.
2. In the AWS Console, navigate to the **IAM** service:
   * Go to **Roles** → **Create Role**.
   * Select **Custom Trust Policy** and paste the copied JSON.
   * Click **Next**, then **Next** again, and name the role **BlynkRole**.
3. Click **Create Role** to finalize.<br>

   <figure><img src="https://1839001309-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBFTVMf7L6S67HOuqVC%2Fuploads%2FbVhO1rynHA8JTRmulaxB%2FAWS%20create%20role.png?alt=media&#x26;token=2b24b36c-b348-4a9a-adac-9c39fb4ebe9e" alt=""><figcaption></figcaption></figure>
4. Next, on the Blynk integration page, copy the **Role Permission JSON**.
5. In the AWS Console, open the created **BlynkRole**, and:
   * Click **Add Permissions** → **Create Inline Policy**.
   * Choose the **JSON Policy Editor** and paste the copied JSON.
   * Enter a name for the policy and click **Create**.

<div><figure><img src="https://1839001309-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBFTVMf7L6S67HOuqVC%2Fuploads%2FsHw08RwnpSGHGKagVaC5%2FAWS%20role%20create%20policy.png?alt=media&#x26;token=7c814e68-df51-4ba4-83ba-82a2abd0582b" alt=""><figcaption></figcaption></figure> <figure><img src="https://1839001309-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBFTVMf7L6S67HOuqVC%2Fuploads%2FZu1aRlxrbOdV84K20dlT%2FAWS%20role%20policy%20creation.png?alt=media&#x26;token=413f02a3-35de-490a-b286-026c7148f212" alt=""><figcaption></figcaption></figure></div>

#### **8. Create a Role Alias**

1. In the AWS Console, navigate to the **IoT Core** service.
2. Go to **Security** → **Role Aliases** → **Create Role Alias**.
3. Enter **BlynkRole** as the role alias name.
4. Select the previously created **BlynkRole** as the associated role.
5. Click **Create** to finalize.

<figure><img src="https://1839001309-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBFTVMf7L6S67HOuqVC%2Fuploads%2FqaIiOtOHdq0gyCIiWxXH%2FAWS%20role%20alias%20creation.png?alt=media&#x26;token=ffb6b83f-6667-42a8-92c4-9188e5d868ea" alt=""><figcaption></figcaption></figure>

Now, in Blynk Console on the integration page click **Connect** and you should see the successful connection message.

<figure><img src="https://1839001309-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBFTVMf7L6S67HOuqVC%2Fuploads%2F5LWanvgjRBpAjuyaHFMb%2FBlynk%20connected%20AWS%20integration.png?alt=media&#x26;token=6bb501ff-d4ab-4835-ae01-ce2c441b6602" alt=""><figcaption></figcaption></figure>

### Configuring the integration

Once the integration is connected, you need to configure it:

1. **Create a Blynk Template**
   * If you haven’t already, [create the Blynk Template](https://docs.blynk.io/en/getting-started/template-quick-setup) that will be used for your devices.
2. **Map the AWS Thing Type to the Blynk Template**
   * Blynk uses the AWS [Thing Type](https://docs.aws.amazon.com/iot/latest/developerguide/thing-types.html) to map devices of the same template to a corresponding set of devices on AWS.
   * Scroll to the bottom of the AWS Integration page, select the **Thing Type** you want to use, and its corresponding **Blynk Template**.
   * Click **Link** to save the selection.

<figure><img src="https://1839001309-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBFTVMf7L6S67HOuqVC%2Fuploads%2FrhdigwCjQTL2dPLOHPx8%2FAWS%20Thing%20Type%20mapping.png?alt=media&#x26;token=6fe6d4ec-31cd-4a86-8963-2121dc4949b5" alt=""><figcaption></figcaption></figure>

### Importing device

After mapping the Thing Type, you can import devices of this type from AWS into Blynk:

1. Click the **Import** button.
2. Select the specific devices you want to import. Alternatively, you can click **Import All** to import all devices of the specified Thing Type from AWS.

<figure><img src="https://1839001309-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBFTVMf7L6S67HOuqVC%2Fuploads%2FO13lWaZ7kmZn98r6ZCyJ%2FAWS%20device%20importing.png?alt=media&#x26;token=cc772b9e-9b8a-4bd3-b50d-5513a6630567" alt=""><figcaption></figcaption></figure>

You can also manually create a device in Blynk by editing its **"Thing Name"** meta field. Ensure the value matches the exact **Thing Name** used in AWS IoT Core and include the device's region.

### Receiving uplinks

Once the integration is successfully connected and the Thing Type is mapped to the corresponding Blynk Template, the system is ready to receive uplink data.

**Configure Datastreams**\
Begin by setting up the datastreams within the Blynk Template. Ensure the names of the datastreams align with the JSON key names in the AWS IoT Device Shadow, and that their types match the JSON value types. Use Virtual Pins, Enum, and Location datastream types.

Below is an example of datastream configurations:<br>

<figure><img src="https://1839001309-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MBFTVMf7L6S67HOuqVC%2Fuploads%2FieAQLxKwUN8wbig3rird%2FBlynk%20template%20datastreams%20settings.png?alt=media&#x26;token=f0079083-cbb6-4fb7-9bea-07e4555b7ddf" alt=""><figcaption></figcaption></figure>

Sample AWS IoT Device Shadow:

```json
{
    "state": {
        "reported": {
            "Temperature": 21.2,
            "Humidity": 43,
            "Location": [-73.935242, 40.730610]
        }
    }
}
```

### Receiving downlinks

To send a downlink to your device, first ensure that the necessary datastream is created. Then, add a control widget to the Web Dashboard or Mobile App.

When the widget is triggered, Blynk will update the device's unnamed shadow desired state with the value provided by the user.

### Next Steps

With a configured Blynk template and a working device, you can now start creating a [Web Dashboard](https://docs.blynk.io/en/blynk.console/templates/dashboard) and [Mobile application](https://docs.blynk.io/en/blynk.apps/constructor).

Additionally, take advantage of other powerful Blynk features, such as [Automations](https://docs.blynk.io/en/concepts/automations), [WebHooks](https://docs.blynk.io/en/blynk.console/settings/developers/webhooks), [Device Connection Lifecycle](https://docs.blynk.io/en/concepts/connection-lifecycle-management), and the [Device HTTPS API](https://docs.blynk.io/en/blynk.cloud/device-https-api), to build more advanced workflows.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.blynk.io/en/hardware-guides/aws-iot-core.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
