in src/AuthDisplay.js [7:43]
function createAndAttachPolicy(id) {
var Iot = new AWS.Iot({region: AWSConfiguration.region, apiVersion: AWSConfiguration.apiVersion, endpoint: AWSConfiguration.endpoint});
var policyName = "amplifyIotReactApp";
var params = {policyName: policyName};
Iot.getPolicy(params , function(err, data) {
if (err) {
var policy = {"Version": "2012-10-17", "Statement": [{"Effect": "Allow", "Action": ["*"],"Resource": ["*"]}]};
var policyDoc = JSON.stringify(policy);
console.log("Creating policy: " + policyName + " with doc: " + policyDoc);
var params = {
policyName: policyName,
policyDocument: policyDoc
};
Iot.createPolicy(params , function(err, data) {
if (err) {
//console.error(err);
if (err.code !== 'ResourceAlreadyExistsException') {
console.log(err);
}
}
else {
console.log("CreatePolicy response=" + data);
attachPolicy(id, policyName);
}
});
}
else {
console.log("Policy " + policyName + " already exists..");
attachPolicy(id, policyName);
}
});
}