I was wondering if anyone has the idea of the best practices on AWS IoT regarding the handling of policies, for example, we could have two different cases:
Case 1: Call a lambda(identity-id as param) which creates a policy on the fly and then attach the policy to the identity id. The policy will contains hardcoded the things name like for example:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:Connect",
"Resource": "arn:aws:iot:us-west-2:XXXX:client/hardcodedClient1"
},
{
"Effect": "Allow",
"Action": [
"iot:Publish",
"iot:Subscribe",
"iot:Receive"
],
"Resource": [
"arn:aws:iot:us-west-2:XXXX:topic/$aws/things/THINGNAME1/*",
"arn:aws:iot:us-west-2:XXXX:topicfilter/$aws/things/THINGNAME1/*"
]
}
]
}
Case 2: by using policy variables like ${iot:ClientId}, ${iot:ThingName}, we can attach one single policy to all the congito-identity-users;
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:Connect",
"Resource": "arn:aws:iot:us-west-2:XXXX:client/${iot:ClientId}"
},
{
"Effect": "Allow",
"Action": [
"iot:Publish",
"iot:Subscribe",
"iot:Receive"
],
"Resource": [
"arn:aws:iot:us-west-2:XXXX:topic/$aws/things/${iot:Connection.Thing.ThingName}/*",
"arn:aws:iot:us-west-2:XXXX:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/*"
]
}
]
}
So, the question is. Which of then is the best practices, but also both of them are secure regarding the Cognito user only is able to interact with his own devices?