def _create_attach_thing_policy()

in gg_group_setup/cmd.py [0:0]


    def _create_attach_thing_policy(cert_arn, thing_policy, iot_client,
                                    policy_name):
        if thing_policy:
            try:
                iot_client.create_policy(
                    policyName=policy_name,
                    policyDocument=thing_policy
                )
            except ClientError as ce:
                if ce.response['Error']['Code'] == 'EntityAlreadyExists':
                    logging.warning(
                        "Policy '{0}' exists. Using existing Policy".format(
                            policy_name))
                else:
                    logging.error("Unexpected Error: {0}".format(ce))
            except BaseException as e:
                logging.error("Error type: {0} message: {1}".format(
                    e, str(type(e))))

            # even if there's an exception creating the policy, try to attach
            iot_client.attach_principal_policy(
                policyName=policy_name,
                principal=cert_arn
            )
            logging.info("Created {0} and attached to {1}".format(
                policy_name, cert_arn))
        else:
            logging.warning("No thing policy to create and attach.")