AWS IoT Core

Receive your device data in AWS IoT Core with a thing, a certificate and a policy.

This guide shows how to receive CeresGate's forwarded device data in AWS IoT Core. CeresGate connects as an AWS IoT "thing" with an X.509 certificate and publishes the data to the MQTT topic you choose; from there, AWS IoT rules can send it on to Lambda, DynamoDB, S3 and other services.

How it works

CeresGate → MQTT (mutual TLS) publish to the uplinktopic → AWS IoT Core → your IoT rules or subscribers
  • For every message a device uploads, CeresGate connects to AWS IoT Core with your certificate, publishes {"IMSI": …, "Payload": …} to the adapter's uplinktopic, and disconnects (see Forwarding format).
  • Each connection's client ID is the adapter's clientid followed by _ and 8 random characters (for example ceresgate_3f2a9c1e). When the policy restricts client IDs, use the clientid followed by a wildcard (see step 2).
  • With QoS 1, the forwarding logs show "Forwarded" once AWS IoT Core acknowledges the message within 5 seconds.

1. Create a thing and a certificate

  1. In the AWS IoT console, choose "All devices" → "Things" → "Create things" and create a thing (for example ceresgate).
  2. For the certificate, choose "Auto-generate a new certificate".
  3. Download these files to upload to CeresGate later:
    • The device certificate (…-certificate.pem.crt)
    • The private key file (…-private.pem.key) — it can be downloaded only once, on this screen, so keep it safe
    • Amazon Root CA 1 (AmazonRootCA1.pem)
  4. Make sure the certificate is Active.

2. Create a policy and attach it to the certificate

The policy decides what the certificate may do. CeresGate needs at least iot:Connect and iot:Publish. Create the policy under "Security" → "Policies", then attach it on the certificate's page with "Attach policies".

Use one of the two versions below, replacing REGION and ACCOUNT_ID with your region and account ID:

A. Restricted to the client ID and topic (recommended)

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "iot:Connect",
      "Resource": "arn:aws:iot:REGION:ACCOUNT_ID:client/ceresgate_*"
    },
    {
      "Effect": "Allow",
      "Action": "iot:Publish",
      "Resource": "arn:aws:iot:REGION:ACCOUNT_ID:topic/ceresgate/uplink"
    }
  ]
}

The ceresgate in client/ceresgate_* must match the adapter's clientid, and topic/ceresgate/uplink its uplinktopic.

B. Unrestricted

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["iot:Connect", "iot:Publish"],
      "Resource": "*"
    }
  ]
}

Version B is simpler, but lets the certificate connect with any client ID and publish to any topic. How far to restrict it is up to your own security practices.

3. Find the endpoint

It's under "Settings" (bottom left of the AWS IoT console) as the "Device data endpoint", and looks like:

a1b2c3d4e5f6g7-ats.iot.ap-northeast-1.amazonaws.com

4. Create the adapter in CeresGate

In the portal's sidebar, choose "Adapter settings" and add an AWS IoT Core adapter:

FieldEnterExample
NameAnything that helps you recognise it
clientidThe start of the client ID, the same as in the policy's client/…_*ceresgate
hostnameThe device data endpoint from step 3a1b2c3d4e5f6g7-ats.iot.ap-northeast-1.amazonaws.com
portThe MQTT over TLS port8883
connectiontimeoutConnection timeout in seconds10
keepaliveMQTT keepalive in seconds60
uplinktopicThe topic device data is published to; must be allowed by the policyceresgate/uplink
qos0 or 1 (AWS IoT Core doesn't support QoS 2); 1 is recommended1
rootcaAmazon Root CA 1 (AmazonRootCA1.pem)
privatekeyThe private key (…-private.pem.key)
certificateThe device certificate (…-certificate.pem.crt)

Certificates and keys are stored encrypted and not shown when editing; to replace them, upload all three files again. Then, in the Adapter column of the device list, choose this adapter for your devices.

5. Check that data arrives

  1. In the AWS IoT console, open the "MQTT test client", enter the uplinktopic (for example ceresgate/uplink) under "Subscribe to a topic" and subscribe.
  2. Let the device send a message; it appears as:
    {"IMSI": "001013453258396", "Payload": "48656c6c6f"}
  3. The portal's "Forwarding logs" also show "Forwarded".

Then create an IoT rule ("Message routing" → "Rules"), for example SELECT * FROM 'ceresgate/uplink', to send the data to your Lambda, DynamoDB or other services.

When forwarding fails or no data arrives

  • Failed to connect to AWS IoT Core: whether the hostname is your account and region's device data endpoint; whether the port is 8883; whether the certificate is Active with the policy attached; whether the three files are in the right fields (the private key matching the certificate); whether the policy allows client IDs starting with the clientid.
  • Failed to send payload to AWS IoT Core.: connected, but AWS IoT Core didn't acknowledge the message within 5 seconds. The most common cause is a policy that doesn't allow publishing to the uplinktopic (AWS IoT Core simply drops the connection); also make sure qos is 0 or 1.
  • Shown as "Forwarded", but no data shows up: whether the topic subscribed to in the MQTT test client is exactly the uplinktopic; whether the subscription existed before the data was sent; whether your IoT rule's SQL selects this topic. With qos 0, AWS IoT Core doesn't acknowledge, so "Forwarded" only means CeresGate sent it.

For other cases, see Forwarding logs and troubleshooting.