# Buggy code
def start(self):
    self._validate_parameters()

    # init with required, conditionally add optional  # TODO - drive from metadata?  Will need better
    metadata = dict(
        api_endpoint=self.api_endpoint,
        cos_endpoint=self.cos_endpoint,
        cos_bucket=self.cos_bucket,
    )

    if self.cos_username:
        metadata["cos_username"] = self.cos_username
    if self.cos_password:
        metadata["cos_password"] = self.cos_password

    runtime = Runtime(
        schema_name=self.schema_name,
        name=self.name,
        display_name=self.display_name,
        metadata=metadata,
    )

    ex_msg = None
    resource = None
    try:
        resource = self.metadata_manager.add(self.name, runtime, replace=self.replace)
    except Exception as ex:
        ex_msg = str(ex)

    if resource:
        print(
            "Metadata for {} runtime '{}' has been written to: {}".format(
                self.schema_name, self.name, resource
            )
        )
    else:
        if ex_msg:
            self._log_and_exit(
                "The following exception occurred while saving metadata '{}' for {} runtime: {}".format(
                    self.name, self.schema_name, ex_msg
                ),
                display_help=True,
            )
        else:
            self._log_and_exit(
                "A failure occurred while saving metadata '{}' for {} runtime.  Check log output.".format(
                    self.name, self.schema_name
                ),
                display_help=True,
            )


# Traceback (KeyError)
[E 14:28:56.246 LabApp] Uncaught exception POST /scheduler?1574720936239 (::1)
HTTPServerRequest(protocol='http', host='localhost:8888', method='POST', uri='/scheduler?1574720936239', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/web.py", line 1697, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "/opt/anaconda3/lib/python3.6/site-packages/ai_workspace/scheduler/handler.py", line 67, in post
cos_username = runtime_configuration.metadata['cos_username']
KeyError: 'cos_username'

# Fixed code
def start(self):
    self._validate_parameters()

    # init with required, conditionally add optional  # TODO - drive from metadata?  Will need better
    metadata = dict(
        api_endpoint=self.api_endpoint,
        cos_endpoint=self.cos_endpoint,
        cos_username=self.cos_username,
        cos_password=self.cos_password,
        cos_bucket=self.cos_bucket,
    )

    runtime = Runtime(
        schema_name=self.schema_name,
        name=self.name,
        display_name=self.display_name,
        metadata=metadata,
    )

    ex_msg = None
    resource = None
    try:
        resource = self.metadata_manager.add(self.name, runtime, replace=self.replace)
    except Exception as ex:
        ex_msg = str(ex)

    if resource:
        print(
            "Metadata for {} runtime '{}' has been written to: {}".format(
                self.schema_name, self.name, resource
            )
        )
    else:
        if ex_msg:
            self._log_and_exit(
                "The following exception occurred while saving metadata '{}' for {} runtime: {}".format(
                    self.name, self.schema_name, ex_msg
                ),
                display_help=True,
            )
        else:
            self._log_and_exit(
                "A failure occurred while saving metadata '{}' for {} runtime.  Check log output.".format(
                    self.name, self.schema_name
                ),
                display_help=True,
            )