コード例 #1
0
def run_notebook(args):
    params = process_params(args.p)
    if args.notebook.startswith("s3://"):
        input_path = args.notebook
        notebook = os.path.basename(args.notebook)
    else:
        input_path = None
        notebook = args.notebook
    try:
        job_name = run.invoke(
            image=args.image,
            input_path=input_path,
            output_prefix=args.output_prefix,
            notebook=notebook,
            parameters=params,
            role=args.role,
            instance_type=args.instance,
            extra_args=load_extra(args.extra),
        )
    # except run.InvokeException as ie:
    #     print(f"Error starting run: {str(ie)}")
    #     return
    except FileNotFoundError as fe:
        print(str(fe))
        return
    print(f"Started processing job {job_name}")
    if args.no_wait:
        return
    status, failure = run.wait_for_complete(job_name)
    print(f"Run finished with status {status}")
    if failure:
        print(failure)
    else:
        run.download_notebook(job_name, args.output_dir)
コード例 #2
0
    def post(self):
        data = self.load_params(["image", "input_path", "notebook"])
        if data is None:
            return

        params = data.get("parameters", {})
        if isinstance(params, str):
            params = json.loads(params)

        kwargs = dict(
            image=data["image"],
            input_path=data["input_path"],
            output_prefix=data.get("output_prefix", None),
            notebook=data["notebook"],
            parameters=params,
            role=data.get("role", None),
        )
        instance_type = data.get("instance_type", None)
        if instance_type:
            kwargs["instance_type"] = instance_type

        try:
            job_name = run.invoke(**kwargs)
            self.json_response(dict(job_name=job_name))
        except botocore.exceptions.ClientError as e:
            self.client_error_response(e)
        except botocore.exceptions.BotoCoreError as e:
            self.botocore_error_response(e)
        except run.InvokeException as ie:
            self.error_response(400, "InvokeException",
                                f"Lambda function returned error: {str(ie)}")
        except ValueError as ve:
            self.error_response(400, "ValueError", str(ve))