@adobe/spacecat-shared-athena-client
v1.9.1
Published
Shared modules of the Spacecat Services - AWS Athena Client
Maintainers
Keywords
Readme
@adobe/spacecat-shared-athena-client
This package provides a shared AWS Athena client for Spacecat Services.
Installation
npm install @adobe/spacecat-shared-athena-clientUsage
import { AWSAthenaClient } from '@adobe/spacecat-shared-athena-client';
import { AthenaClient } from '@aws-sdk/client-athena';
// Create a client directly
const client = new AthenaClient({ region: 'us-east-1' });
const athenaClient = new AWSAthenaClient(client, 's3://your-temp-bucket/', console);
// Or create from context
const context = {
env: { AWS_REGION: 'us-east-1' },
log: console
};
const athenaClient = AWSAthenaClient.fromContext(context, 's3://your-temp-bucket/');
// Execute a query and get results
const results = await athenaClient.query(
'SELECT * FROM your_table',
'your_database',
'Example query'
);
// Execute a DDL operation without results
const queryId = await athenaClient.execute(
'CREATE TABLE your_table ...',
'your_database',
'Create table'
);Configuration Options
The client accepts the following options:
backoffMs(default: 100) - Base backoff time in milliseconds for retriesmaxRetries(default: 3) - Maximum number of retry attemptspollIntervalMs(default: 1000) - Interval between query status checksmaxPollAttempts(default: 120) - Maximum number of status check attempts
API
constructor(client, tempLocation, log, opts?)
Creates a new Athena client instance.
client: AWS Athena SDK client instancetempLocation: S3 URI for temporary query resultslog: Logger object with info/warn/error/debug methodsopts: Optional configuration options
static fromContext(context, tempLocation, opts?)
Creates a client from a context object.
context: Object containing env.AWS_REGION and logtempLocation: S3 URI for temporary query resultsopts: Optional configuration options
query(sql, database, description?, opts?)
Executes a query and returns parsed results.
sql: SQL query stringdatabase: Target database namedescription: Optional query description for logsopts: Optional execution options- Returns: Promise of parsed results
execute(sql, database, description?, opts?)
Executes a query without returning results (for DDL operations).
sql: SQL query stringdatabase: Target database namedescription: Optional query description for logsopts: Optional execution options- Returns: Promise query execution ID
Contributing
Contributions are welcomed! Read the Contributing Guide for more information.
Licensing
This project is licensed under the Apache V2 License. See LICENSE for more information.
