Establishing a Connection with the AuraJobV2 Endpoint
This section describes how to create a session connection with the AuraJobV2 endpoint by calling ai_lake.connect(). All subsequent data operations are performed based on this connection.
Prerequisites
- The Aura DataFrame SDK has been installed. For details, see Obtaining and Installing the Aura DataFrame SDK.
- An AuraJobV2 endpoint has been created, and the endpoint name has been obtained. For details, see Creating an Aura Engine Endpoint.
- A LakeFormation instance has been created, where a catalog and a database are ready. For details, see Creating a LakeFormation Instance and Planning Metadata.
- A parallel file system has been created. For details, see Creating a Parallel File System.
- The parameters in os.getenv() involved in the code have been configured as environment variables.
- The Python 3.11 has been installed.
Example
import os
import logging
from aura_frame.multimodal import ai_lake
con = ai_lake.connect(
aura_endpoint=os.getenv("aura_endpoint"), # Endpoint where the AuraJobV2 endpoint is located
aura_endpoint_id=os.getenv("aura_endpoint_id"), # AuraJobV2 endpoint ID
aura_endpoint_name=os.getenv("aura_endpoint_name"),# AuraJobV2 endpoint name
aura_workspace_id=os.getenv("aura_workspace_id"), # Workspace ID
lf_catalog_name=os.getenv("lf_catalog_name"), # LakeFormation Catalog name
access_key=os.getenv("access_key"), # Access Key ID (AK)
secret_key=os.getenv("secret_key"), # Secret Key (SK)
default_database="postgres", # LakeFormation database name
use_single_cn_mode=True, # Whether to enable the single-CN mode
logging_level=logging.INFO # Set the log level.
) The parameters of ai_lake.connect() are as follows:
| Parameter | Description | Type | Default Value |
|---|---|---|---|
| aura_endpoint | Specifies the endpoint information of the connection. For details, see Regions and Endpoints. | str | None |
| aura_endpoint_id | Specifies the ID of the AuraJobV2 endpoint to be connected. | str | None |
| aura_endpoint_name | Specifies the name of the AuraJobV2 endpoint to be connected. | str | None |
| aura_workspace_id | Specifies the ID of the workspace where the AuraJobV2 endpoint to be connected is located. | str | None |
| lf_catalog_name | Specifies the name of the LakeFormation catalog to be connected. | str | None |
| access_key | Specifies the Access Key ID (AK) of the connection. | str | None |
| secret_key | Specifies the Secret Key (SK) of the connection. | str | None |
| default_database | Specifies the name of the default database to be connected. | str | None |
| use_single_cn_mode | Specifies whether to enable the single-CN mode. | bool | False |
| logging_level | Specifies the log level. | int | logging.INFO |
The following example demonstrates the complete process of establishing a connection and verifying connectivity:
import os
import logging
from aura_frame.multimodal import ai_lake
con = ai_lake.connect(
aura_endpoint=os.getenv("aura_endpoint"), # Endpoint where the AuraJobV2 endpoint is located, for example:
aura_endpoint_id=os.getenv ("aura_endpoint_id"), # AuraJobV2 endpoint ID
aura_endpoint_name=os.getenv("aura_endpoint_name"), # AuraJobV2 endpoint name
aura_workspace_id=os.getenv("aura_workspace_id"), # Workspace ID
lf_catalog_name=os.getenv ("lf_catalog_name"), # LakeFormation Catalog name
lf_instance_id=os.getenv ("lf_instance_id"), # LakeFormation instance ID
project_id=os.getenv ("project_id"), # Project ID
access_key=os.getenv("access_key"), # Access Key ID (AK)
secret_key=os.getenv("secret_key"), # Secret Key (SK)
default_database="postgres", # Default database
use_single_cn_mode=True, # Whether to enable the single-CN mode
logging_level=logging.INFO, # Set the log level.
)
try:
with con.sql("select 1;") as cur: # Execute the SQL statement to verify the connectivity.
result = cur.fetchall()
print("Connection successful. Result of select 1:", result)
finally:
con.close() # Close the connection. Helpful Links
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot