<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def upsert(self):
 """ The main event of the utility. Create or update a Cloud Formation stack. Injecting properties where needed Args: None Returns: True if the stack create/update is started successfully else False if the start goes off in the weeds. Exits: If the user asked for a dryrun exit(with a code 0) the thing here. There is no point continuing after that point. """


        required_parameters = []
        self._stackParameters = []

        try:
            self._initialize_upsert()
        except Exception:
            return False

        try:
            available_parameters = self._parameters.keys()

            for parameter_name in self._template.get('Parameters', {}):
                required_parameters.append(str(parameter_name))

            logging.info(' required parameters: ' + str(required_parameters))
            logging.info('available parameters: ' + str(available_parameters))

            parameters = []
            for required_parameter in required_parameters:
                parameter = {}
                parameter['ParameterKey'] = str(required_parameter)

                required_parameter = str(required_parameter)
                if required_parameter in self._parameters:
                    parameter['ParameterValue'] = self._parameters[required_parameter]
                else:
                    parameter['ParameterValue'] = self._parameters[required_parameter.lower()]

                parameters.append(parameter)

            if not self._analyze_stuff():
                sys.exit(1)

            if self._config.get('dryrun', False):
                logging.info('Generating change set')
                set_id = self._generate_change_set(parameters)
                if set_id:
                    self._describe_change_set(set_id)

                logging.info('This was a dryrun')
                sys.exit(0)

            self._tags.append({"Key": "CODE_VERSION_SD", "Value": self._config.get('codeVersion')})
            self._tags.append({"Key": "ANSWER", "Value": str(42)})
            if self._updateStack:
                stack = self._cloudFormation.update_stack(
                    StackName=self._config.get('environment', {}).get('stack_name', None),
                    TemplateURL=self._templateUrl,
                    Parameters=parameters,
                    Capabilities=['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM'],
                    Tags=self._tags,
                    ClientRequestToken=str(uuid.uuid4())
                )
                logging.info('existing stack ID: {}'.format(stack.get('StackId', 'unknown')))
            else:
                stack = self._cloudFormation.create_stack(
                    StackName=self._config.get('environment', {}).get('stack_name', None),
                    TemplateURL=self._templateUrl,
                    Parameters=parameters,
                    Capabilities=['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM'],
                    Tags=self._tags,
                    ClientRequestToken=str(uuid.uuid4())
                )
                logging.info('new stack ID: {}'.format(stack.get('StackId', 'unknown')))
        except Exception as x:
            if self._verbose:
                logging.error(x, exc_info=True)
            else:
                logging.error(x, exc_info=False)

            return False

        return True