TLS Issue - Workers to AWS IoT Core

I am trying to communicate to the AWS IoT core HTTPS endpoint through a cloudflare worker (using hono).

I created a certificate and I tested successfully sending a message with curl and the downloaded certificates - https://docs.aws.amazon.com/iot/latest/developerguide/http.html

curl --tlsv1.2 \
    --cacert Amazon-root-CA-1.pem \
    --cert device.pem.crt \
    --key private.pem.key \
    --request POST \
    --data "{ \"message\": \"Hello, world\" }" \
    "https://IoT_data_endpoint:8443/topics/topic?qos=1"


Then I configured the binding with wrangler

pnpx wrangler mtls-certificate upload --cert device.pem.crt --key private.pem.key --name AWS_IOT


And then I configured an endpoint in hono

iotPublish.post("/", async (c) => {
  try {
    let topic = "test";
    let message = { message: "hello" };

    return await c.env.AWS_IOT.fetch(
      `https://xxxxxx.iot.eu-central-1.amazonaws.com:8443/topics/topic?qos=1`,
      {
        method: "POST",

        body: JSON.stringify(message),
      }
    );
  } catch (e) {
    console.log(e);
    return Response.json({ error: JSON.stringify(e) }, { status: 500 });
  }
});


The result is always
{
  "message": "Missing authentication",
  "traceId": "8c6b18f4-b3d5-42c7-8edb-e2b0bbc09ad3"
}


Please help
Learn how AWS IoT clients can publish messages by making requests to the REST API using HTTPS.
Was this page helpful?