Load Data into Autonomous Database from AWS S3

This example shows you how to load data from Amazon S3 object storage to Autonomous Database.

This example uses AWS access credentials for user account authentication and an object URL for accessing the object in S3 bucket.

To load data from an Amazon S3 bucket:
  1. Create credentials for AWS user account in the Autonomous Database

  2. Copy data from the Amazon S3 bucket to the database

Follow these for step-by-step details for loading data.

Prepare for Loading Data from AWS S3

Verify the prerequisites and prepare for loading data from Amazon S3.

Prerequisites

A data file, for example, data.txt exists in the Amazon S3 bucket that you can import. The sample file in this example has the following contents:
1,Direct Sales
2,Tele Sales
3,Catalog
4,Internet
5,Partners

On the AWS side, log in to your AWS account and do the following:

  1. Grant access privileges to the AWS IAM user for the Amazon S3 bucket.
  2. Create an access key for the user.
    For more information, see Managing access keys for IAM users.
  3. Obtain an object URL for the data file stored in the Amazon S3 bucket.
    For more information, see Accessing and listing an Amazon S3 bucket.

Steps for Loading Data for AWS S3

Run these steps to load data from Amazon S3 to Autonomous Database.

  1. Store the AWS access credentials in your Autonomous Database and specify a credential name. This enables the database to authenticate with your AWS user account and access the items in the S3 bucket.
    SET DEFINE OFF
    BEGIN
      DBMS_CLOUD.CREATE_CREDENTIAL(
        credential_name => 'AWS_CRED_NAME',
        username => 'AKOOADWCUSER_EXAMPLE',
        password => '7MymZxpyooooooMyAccessKeyooooooooexample'
      );
    END;
    /

    Note:

    Here, the user name is your AWS Access key ID and the password is your user access key.

    For detailed information about the parameters, see CREATE_CREDENTIAL Procedure.

    Optionally, you can test the access to S3 bucket as shown in this example.

    SELECT * FROM dbms_cloud.list_objects('AWS_CRED_NAME', ' https://aws-bucket-01.s3.amazonaws.com/');
    
  2. Create a table in your database where you want to load the data.
    CREATE TABLE mytable (id NUMBER, name VARCHAR2(64));
    
  3. Import data from the Amazon S3 bucket to your Autonomous Database.
    Specify the table name and the AWS credential name followed by the S3 object URL.
    BEGIN
          DBMS_CLOUD.COPY_DATA(
              table_name => 'mytable',
              credential_name => 'AWS_CRED_NAME',
              file_uri_list => https://aws-bucket-01.s3.amazonaws.com/data.txt',
              format => json_object('delimiter' value ',')
          );
    END;
    /

    For detailed information about the parameters, see COPY_DATA Procedure and COPY_DATA Procedure for Avro, ORC, or Parquet Files.

You have successfully imported data from Amazon S3 to your Autonomous Database. You can run this statement and verify the data in your table.
SELECT * FROM mytable;
ID  NAME
--  –-------------
 1  Direct Sales
 2  Tele Sales
 3  Catalog
 4  Internet
 5  Partners

For more information about loading data, see Load Data from Files in the Cloud.