def create_core()

in gg_group_setup/cmd.py [0:0]


    def create_core(self, thing_name, config_file, region=None,
                    cert_dir=None, account_id=None,
                    policy_name='ggc-default-policy', profile_name=None):
        """
        Using the `thing_name` value, creates a Thing in AWS IoT, attaches and
        downloads new keys & certs to the certificate directory, then records
        the created information in the local config file for inclusion in the
        Greengrass Group as a Greengrass Core.

        :param thing_name: the name of the thing to create and use as a
            Greengrass Core
        :param config_file: config file used to track the Greengrass Core in the
            group
        :param region: the region in which to create the new core.
            [default: us-west-2]
        :param cert_dir: the directory in which to store the thing's keys and
            certs. If `None` then use the current directory.
        :param account_id: the account_id in which to create the new core.
            [default: None]
        :param policy_name: the name of the policy to associate with the device.
            [default: 'ggc-default-policy']
        :param profile_name: the name of the `awscli` profile to use.
            [default: None]
        """
        config = GroupConfigFile(config_file=config_file)
        if config.is_fresh() is False:
            raise ValueError(
                "Config file already tracking previously created core or group"
            )
        if region is None:
            region = self._region
        if account_id is None:
            account_id = self._account_id
        keys_cert, thing = self.create_thing(thing_name, region, cert_dir)

        cert_arn = keys_cert['certificateArn']
        config['core'] = {
            'thing_arn': thing['thingArn'],
            'cert_arn': cert_arn,
            'cert_id': keys_cert['certificateId'],
            'thing_name': thing_name
        }
        logging.debug("create_core cfg:{0}".format(config))
        logging.info("Thing:'{0}' associated with cert:'{1}'".format(
            thing_name, cert_arn))
        core_policy = self.get_core_policy(
            core_name=thing_name, account_id=account_id, region=region)
        iot_client = _get_iot_session(region=region, profile_name=profile_name)
        self._create_attach_thing_policy(
            cert_arn, core_policy,
            iot_client=iot_client, policy_name=policy_name
        )
        misc = config['misc']
        misc['policy_name'] = policy_name
        config['misc'] = misc