This guide introduces the steps to take in purpose of connecting Milesight IoT LoRaWAN end-devices to AWS IoT Core for LoRaWAN. If you don’t have an AWS account, refer to the instructions in the guide here.

The high-level steps to get started with AWS IoT Core for LoRaWAN are as follows:

  1. Add LoRaWAN gateway on AWS IoT Link
  2. Add the end-device

These steps are detailed below. For additional help, refer to the AWS LoRaWAN developer guide.

Once setup is completed, provisioned devices can join the network and start to send messages. Messages from devices can then be received by AWS IoT Core for LoRaWAN and forwarded to the IoT Rules Engine.


  • An AWS account
  • LoRaWAN gateway (e.g., UG56, UG6x) that’s already connected to AWS IoT for LoRaWAN
  • Milesight LoRaWAN end device whose frequency plan matches the gateway’s LoRaWAN region
  • MAC Version. This must be one of the following that are supported on AWS (By default, Milesight devices use v1.0.3)
    • 1.0.2
    • 1.0.3
  • Activation method to use (By default, Milesight devices use OTAA v1.0.x)
    • OTAA v1.0.x
    • ABP v1.0.x
  • Copy the following information from device’s payload structure on Milesight IoT document center:
    • For OTAA v1.0.x devices: DevEUI, AppKey, AppEUI
    • For ABP v1.0.x devices: DevEUI, DevAddr, NwkSkey, AppSkey


Verify Profiles

AWS IoT Core for LoRaWAN supports device profiles and service profiles. Device profiles contain the communication and protocol parameter values the device needs to communicate with the network server. Service profiles describe the communication parameters the device needs to communicate with the application server.

Some pre-defined profiles are available for device and service profiles. Before proceeding, verify that these profile settings match the devices you will be setting up to work with AWS IoT Core for LoRaWAN.

  • Navigate to the AWS IoT console. In the navigation pane, choose Manage > LPWAN devices > Profiles.
  • In the Device Profiles section, there are some pre-defined profiles listed.
  • Check each of the profiles to determine if one of them will work for you. If not, select Add device profile and set up the parameters as needed. For example:
    • MacVersion 1.0.3
    • RegParamsRevision Regional Parameters v1.0.2rB
    • MaxEirp 10
    • MaxDutyCycle 10
    • RfRegion US915
    • SupportsJoin true
  • In the Service Profiles section, there are some pre-defined profiles listed. Check each of the profiles to determine if one of them will work for you. If not, select Add service profile and set up the parameters as needed. Proceed only if you have a device and service profile that will work for you.

Set up a Destination for device traffic

Since most LoRaWAN devices don't send data to AWS IoT Core for LoRaWAN in a format that can be consumed by AWS services, traffic must firstly be sent to a Destination. A Destination represents the AWS IoT rule that processes a device's data for use by AWS services. This AWS IoT rule contains the SQL statement that selects the device's data and the topic rule actions that send the result of the SQL statement to the services that will use it. For more information on Destinations, refer to the AWS LoRaWAN developer guide.

  • Navigate to Manage > LPWAN devices > Destinations page, choose Add destination.
  • Under Destination details enter ProcessLoRa as the Destination name, and an appropriate description under Destination description – optional.

NOTE: The Destination name can be anything. For getting started and consistency, choose ProcessLoRa for the first integration with AWS IoT Core for LoRaWAN.

  • For Rule name enter LoRaWANRouting. Ignore the section Rules configuration – Optional for now.
  • In the Permissions section select the IAM role you had created earlier from the drop-down.
  • Choose Add Destination. You will see a message “Destination added”, indicating the destination has been successfully added.

Register the Device

Now register an endpoint device with AWS IoT Core for LoRaWAN as follows:

  • Go to the AWS IoT console.
  • Navigate to Manage > LPWAN devices > Devices page
  • Choose Add wireless device
  • On the Add device page, select the LoRaWAN specification version as OTAA v1.0.x or ABP v1.0.x in the drop-down under Wireless device specification.
  • Under LoRaWAN specification and wireless device configuration, enter the DevEUI and confirm it in the Confirm DevEUI
  • Enter the remaining fields as per the OTAA/ABP choice you made above.
  • Enter a name for your device in the Wireless device name – optional field
  • In the Profiles section, under Wireless device profile, find a drop-down option that corresponds to your device and region.

NOTE: Compare your device details to ensure the device profile is correct. If there are no valid default options, you will have to create a new profile (see the section Verify Profiles).

  • Choose the destination you created earlier (ProcessLoRa) from the drop-down under Choose destination.
  • Choose Next
  • Choose Add device
  • You will see a message saying “Wireless device added”, indicating that your device has been set up successfully.

Create lambda function for destination rule

Create the lambda function to process device messages processed by the destination rule.

  • Go to the AWS Lambda console.
  • Click on Functions in the navigation pane.
  • Click on Create function.
  • Select Author from scratch. Under Basic information, enter the function name “am100decoder” for instance and choose Node.js 12.x. from the drop-down under Runtime.
  • Click on Create function.
  • Click the function you created, Under Code tab, follow the guide of README from this link to make the index.js code.
  • Once the code has been pasted, choose Deploy to deploy the lambda code.

After deploying the code, you need to change the lambda role policy permission as following steps:

  • Navigate to Configuration > Permissions tab of the lambda function
  • Under Execution role, click on the Role name to go to the IAM Roles page
  • On the Permissions tab, find the policy name and click on it
  • Choose Edit policy, and choose the JSON tab
  • Append the following to the Statement section of the policy to allow publishing to AWS IoT.
  "Effect": "Allow",
  "Action": [
"Resource": [

  • Choose Review Policy, then Save changes.

After saving the policy, go back to corresponding AWS Lambda function page to create a test event that will allow you to test the functionality of the lambda function.

  • Under Test tab, select New event
  • Enter a name for the test event under Event name
  • Copy the following AM107 sample payload and paste in the area under Event name:
    "WirelessDeviceId": "ab35b5ec-00b6-4c02-9bec-1e4efa4c7ba1",
    "PayloadData": "A2cHAQRocgZlRABeAVAABWosAAd9ZgIIfQwACXN5Jw==",
    "WirelessMetadata": {
        "LoRaWAN": {
            "DataRate": "2",
            "DevEui": "24e124128a390388",
            "FCnt": 65,
            "FPort": 85,
            "Frequency": "865500000",
            "Gateways": [{
                "GatewayEui": "24e124fffef128ea",
                "Rssi": -33,
                "Snr": 10.5
           "Timestamp": "2021-03-16T07:37:18Z"

  • Click Save changes to save the event.

  • Navigate to the AWS IoT Core console, choose Test on the navigation pane, and select MQTT test client.
  • Configure the MQTT test client to subscribe to “#” (all topics)
  • Click on Test in the Lambda function page to generate the test event you just created
  • Verify the published data in the AWS IoT Core MQTT Test client