I was trying to generate an IOT policy using AWS SDK for Node JS using the following code.
var params = {
policyDocument: 'file:///tmp/mypolicy.json',
policyName: 'my_custom_policy'
};
iot.createPolicy(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
But running the script returns the following exception.
[MalformedPolicyException: Policy document is Malformed]
message: 'Policy document is Malformed',
code: 'MalformedPolicyException', etc
I have tried /tmp/mypolicy.json
, ./mypolicy.json
(after copying json file in the script's folder) etc. But the exception keeps on happaning.
The contents of the json is given below (Copied from Amazon official documentation).
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action":["iot:*"],
"Resource": ["*"]
}]
}
Any idea about the correct method to specify policyDocument and generate IOT policy?