- Newest
- Most votes
- Most comments
The policy provided in the AI generated answer is correct for what you want to achieve, assuming the clientId passed used by the code on the device is exactly the same as the thing name.
The error you published is related to the connection attempt. Could you confirm that if you change the first statement to
{
"Effect": "Allow",
"Action": "iot:Connect",
"Resource": "*"
}
you get a different error?
When creating a less permissive policy for AWS IoT Core, there are a few key points to consider:
-
Client ID restriction: To ensure that only the specific device can connect, you should restrict the iot:Connect action to use the thing name as the client ID. This can be done using the ${iot:Connection.Thing.ThingName} policy variable.
-
Topic structure: Make sure your topic structure in the policy exactly matches what your device is trying to publish to or subscribe to. The wildcard (*) at the end allows for subtopics.
-
Resource ARNs: Ensure that your account ID and region are correct in the resource ARNs.
Based on your requirements, here's a suggested policy:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iot:Connect", "Resource": "arn:aws:iot:eu-west-3:YOUR_ACCOUNT_ID:client/${iot:Connection.Thing.ThingName}", "Condition": { "StringEquals": { "iot:ClientId": "${iot:Connection.Thing.ThingName}" } } }, { "Effect": "Allow", "Action": "iot:Publish", "Resource": "arn:aws:iot:eu-west-3:YOUR_ACCOUNT_ID:topic/TOP/${iot:Connection.Thing.ThingName}/*" }, { "Effect": "Allow", "Action": "iot:Subscribe", "Resource": "arn:aws:iot:eu-west-3:YOUR_ACCOUNT_ID:topicfilter/TOP/${iot:Connection.Thing.ThingName}/*" }, { "Effect": "Allow", "Action": "iot:Receive", "Resource": "arn:aws:iot:eu-west-3:YOUR_ACCOUNT_ID:topic/TOP/${iot:Connection.Thing.ThingName}/*" } ] }
This policy:
- Restricts the Connect action to only allow connections with a client ID matching the thing name.
- Allows publishing, subscribing, and receiving on topics that start with "/TOP/[ThingName]/" and can have any subtopics after that.
- Uses the ${iot:Connection.Thing.ThingName} variable to dynamically insert the thing name into the topic structure.
Make sure to replace YOUR_ACCOUNT_ID with your actual AWS account ID.
If you're still experiencing issues after applying this policy, double-check that:
- The thing name in AWS IoT Core exactly matches the client ID your device is using to connect.
- The topic structure in your device code matches what's specified in the policy.
- The certificate associated with the thing is activated and properly attached to both the thing and this policy.
Remember, when using the ${iot:Connection.Thing.ThingName} variable, the client ID used to connect must exactly match the thing name for the policy to work correctly.
Sources
Policy Thing Problem | AWS re:Post
New needed IoT publish permissions from Lambda | AWS re:Post
I've just try the solution privide by IA, same result I got an AUTHORIZATION_FAILURE. The only working solution is usinng
*
, as soon as I try to add omething other than*
I'm rejected{ "timestamp": "2025-05-05 13:28:51.911", "logLevel": "ERROR", "traceId": "-----------", "accountId": "same_as_my_arn", "status": "Failure", "eventType": "Connect", "protocol": "MQTT", "clientId": "same_as_my_thing_name", "principalId": "------------", "sourceIp": "removed", "sourcePort": 49617, "reason": "AUTHORIZATION_FAILURE", "details": "Authorization Failure" }
Relevant content
- asked 18 hours ago
- AWS OFFICIALUpdated 6 months ago
No I have the same error, for example if I do
Everything works but as soon as I try to add something after
topicfiler
inSubscribe
, I got an AUTHORIZATION_FAILUREExample
Not working
Can you confirm that in the error you get
"eventType": "CONNECT"
even with the modified policy? If you can, please provide a copy of the error.Hello, For now I confirm I'm authorized to connect if I do
In my policy, and I'm also able to subscride and publich using specifig topic path.
But as soon as I try to restricted my connect rules, I'm rejected. For example if I do
I got this error in CloudWatch
I've verified, ACCOUNT_ID and CLIENT_ID are good, number shown in my log and number in my policy are the same. My things is name same as my CLIENT_ID
Hi,
am I correct that if you leave the wildcard in the
iot:Connect
statement, your device can connect, subscribe, publish and receive messages? That is, when using the following policy everything works?If this is not the case, please copy the error you get. Thanks.
Could you also share the values of these 3 variables used by the Nordic library: