Skip to main content

AWS Jupyter Proxy

Build Version Code style: black

A Jupyter server extension to proxy requests with AWS SigV4 authentication.

Overview

This server extension enables the usage of the AWS JavaScript/TypeScript SDK to write Jupyter frontend extensions without having to export AWS credentials to the browser.

A single /awsproxy endpoint is added on the Jupyter server which receives incoming requests from the browser, uses the credentials on the server to add SigV4 authentication to the request, and then proxies the request to the actual AWS service endpoint.

All requests are proxied back-and-forth as-is, e.g., a 4xx status code from the AWS service will be relayed back as-is to the browser.

NOTE: This project is still under active development

Install

Installing the package from PyPI will install and enable the server extension on the Jupyter server.

pip install aws-jupyter-proxy

Usage

Using this requries no additional dependencies in the client-side code. Just use the regular AWS JavaScript/TypeScript SDK methods and add any dummy credentials and change the endpoint to the /awsproxy endpoint.

    import * as AWS from 'aws-sdk';
    import SageMaker from 'aws-sdk/clients/sagemaker';

    // Reusable function to add the XSRF token header to a request
    function addXsrfToken<D, E>(request: AWS.Request<D, E>) {
      const cookie = document.cookie.match('\\b' + '_xsrf' + '=([^;]*)\\b');
      const xsrfToken = cookie ? cookie[1] : undefined;
      if (xsrfToken !== undefined) {
        request.httpRequest.headers['X-XSRFToken'] = xsrfToken;
      }
    }

    // These credentials are *not* used for the actual AWS service call but you have
    // to provide any dummy credentials (Not real ones!)
    AWS.config.secretAccessKey = 'IGNOREDIGNORE/IGNOREDIGNOREDIGNOREDIGNOR';
    AWS.config.accessKeyId = 'IGNOREDIGNO';

    // Change the endpoint in the client to the "awsproxy" endpoint on the Jupyter server.
    const proxyEndpoint = 'http://localhost:8888/awsproxy';

    const sageMakerClient = new SageMaker({
        region: 'us-west-2',
        endpoint: proxyEndpoint,
    });

    // Make the API call!
    await sageMakerClient
        .listNotebookInstances({
            NameContains: 'jaipreet'
        })
        .on('build', addXsrfToken)
        .promise();

Usage with S3

For S3, use the s3ForcePathStyle parameter during the client initialization

    import S3 from 'aws-sdk/clients/s3';

    const s3Client = new S3({
        region: 'us-west-2',
        endpoint: proxyEndpoint,
        s3ForcePathStyle: true,
        s3DisableBodySigning:false // for https
    });

    await s3Client
        .getObject({
            Bucket: 'my-bucket',
            Key: 'my-object'
        })
        .on('build', addXsrfToken)
        .promise();

Whitelisting

On the server, the AWS_JUPYTER_PROXY_WHITELISTED_SERVICES environment variable can be used to whitelist the set of services allowed to be proxied through. This is opt-in - Not specifying this environment variable will whitelist all services.

export AWS_JUPYTER_PROXY_WHITELISTED_SERVICES=sagemaker,s3
jupyter-lab

Development

Install all dev dependencies

pip install -e ".[dev]"
jupyter serverextension enable --py aws_jupyter_proxy --sys-prefix

Run unit tests using pytest

pytest tests/unit

License

This library is licensed under the Apache 2.0 License.

Metadata

Release files for aws-jupyter-proxy 0.3.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-jupyter-proxy 0.3.7
File Size Uploaded Provenance
aws_jupyter_proxy-0.3.7.tar.gz 17.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-jupyter-proxy 0.3.7
File Interpreter ABI Platform
aws_jupyter_proxy-0.3.7-py3-none-any.whl Python 3 none any Details

Total release size: 36.7 kB

Release files / aws_jupyter_proxy-0.3.7.tar.gz

Download URL aws_jupyter_proxy-0.3.7.tar.gz
Size 17.8 kB
Tags Source
SHA-256 checksum
How to use checksums
81085057b7759425e17a07234af6b78cebee6484bffe33091d243c8316aa02ff
BLAKE2b-256 checksum
How to use checksums
28fc29dba72ca93cc6547c6a675ca51defcc7172ec561ee671659e628d2f7f35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / aws_jupyter_proxy-0.3.7-py3-none-any.whl

Download URL aws_jupyter_proxy-0.3.7-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb6dae98f36b9efc134004df04d1234011d55a147bb2465e871d309fc3ef3520
BLAKE2b-256 checksum
How to use checksums
2086840a95574b9aec171a0f1010fc97789407eba901b57ee42683eb09c97751
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Security for aws-jupyter-proxy 0.3.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page