이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 2. Creating an S3 client


To interact with data stored in an S3-compatible object store from a workbench, you must create a local client to handle requests to the AWS S3 service by using an AWS SDK such as Boto3.

Boto3 is an AWS SDK for Python that provides an API for creating and managing AWS services, such as AWS S3 or S3-compatible object storage.

After you have configured a Boto3 client for the S3 service from a workbench, you can connect and work with data in your S3-compatible object store.

Prerequisites

  • You have access to an S3-compatible object store.
  • You have stored files in a bucket on your object store.
  • You have logged in to Red Hat OpenShift AI.
  • You have created a data science project.
  • You have added a workbench to the project using a workbench image.
  • You have configured a connection for your workbench based on the credentials of your S3-compatible storage account.

Procedure

  1. From the OpenShift AI dashboard, click Data science projects.
  2. Click the name of the project that contains the workbench.
  3. Click the Workbenches tab.
  4. If the status of the workbench is Running, skip to the next step.

    If the status of the workbench is Stopped, in the Status column for the workbench, click Start.

    The Status column changes from Stopped to Starting when the workbench server is starting, and then to Running when the workbench has successfully started.

  5. Click the open icon ( The open icon ) next to the workbench.

    Your Jupyter environment window opens.

  6. On the toolbar, click the Git Clone icon and then select Clone a Repository.
  7. In the Clone a repo dialog, enter the following URL https://github.com/opendatahub-io/odh-doc-examples.git and then click Clone.
  8. In the file browser, select the newly-created odh-doc-examples folder.
  9. Double-click the newly created storage folder.

    You see a Jupyter notebook named s3client_examples.ipynb.

  10. Double-click the s3client_examples.ipynb file to launch the Jupyter notebook.

    The Jupyter notebook opens. You see code examples for the following tasks:

    • Installing Boto3 and required Boto3 libraries
    • Creating an S3 client session
    • Creating an S3 client connection
    • Listing files
    • Creating a bucket
    • Uploading a file to a bucket
    • Downloading a file from a bucket
    • Copying files between buckets
    • Deleting an object from a bucket
    • Deleting a bucket
  11. In the Jupyter notebook, locate the following instructions to install Boto3 and its required libraries, and run the code cell:

    #Upgrade pip to the latest version
    !pip3 install --upgrade pip
    
    #Install Boto3
    !pip3 install boto3
    
    #Install Boto3 libraries
    import os
    import boto3
    from botocore.client import Config
    from boto3 import session
    
    #Check Boto3 version
    !pip3 show boto3

    The instructions in the code cell update the Python Package Manager (pip) to the latest version, install Boto3 and its required libraries, and display the version of Boto3 installed.

  12. Locate the following instructions to create an S3 client and session. Run the code cell.

    #Creating an S3 client
    #Define credentials
    key_id = os.environ.get('AWS_ACCESS_KEY_ID')
    secret_key = os.environ.get('AWS_SECRET_ACCESS_KEY')
    endpoint = os.environ.get('AWS_S3_ENDPOINT')
    region = os.environ.get('AWS_DEFAULT_REGION')
    
    #Define client session
    session = Boto3.session.Session(aws_access_key_id=key_id,
    aws_secret_access_key=secret_key)
    
    #Define client connection
    s3_client = Boto3.client('s3', aws_access_key_id=key_id,
    aws_secret_access_key=secret_key,aws_session_token=None,
        config=Boto3.session.Config(signature_version='s3v4'),
                            endpoint_url=endpoint,
                            region_name=region)

    The instructions in the code cell configure an S3 client and establish a session to your S3-compatible object store.

Verification

  • To use the S3 client to connect to your object store and list the available buckets, locate the following instructions to list buckets and run the code cell:

    s3_client.list_buckets()

    A successful response includes a HTTPStatusCode of 200 and a list of buckets similar to the following output:

    'HTTPStatusCode': 200,
    'Buckets': [{'Name': 'aqs086-image-registry',
    'CreationDate': datetime.datetime(2024, 1, 16, 20, 21, 36, 244000, tzinfo=tzlocal  ())}]
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2026 Red Hat
맨 위로 이동