Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
stepinfwd committed Jun 7, 2022
1 parent 2cc4240 commit 4fddb13
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
41 changes: 29 additions & 12 deletions plugins/packages/athena/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ export default class Athena implements QueryService {
const AthenaExpress = require('athena-express'),
AWS = require('aws-sdk'),
awsCredentials = {
region: 'YOUR_AWS_REGION',
accessKeyId: 'YOUR_AWS_ACCESS_KEY_ID',
secretAccessKey: 'YOUR_AWS_SECRET_ACCESS_KEY',
region: sourceOptions.region,
accessKeyId: sourceOptions.access_key,
secretAccessKey: sourceOptions.secret_key,
};

AWS.config.update(awsCredentials);

const athenaExpressConfig = {
aws: AWS,
s3: 's3://my-bucket-for-storing-athena-results-us-east-1',
s3: sourceOptions.output_location,
getStats: true,
};

const athenaExpress = new AthenaExpress(athenaExpressConfig);
const myQuery = {
sql: 'SELECT elb_name, request_port, request_ip FROM elb_logs LIMIT 3',
db: 'sampledb',
sql: queryOptions.query,
db: sourceOptions.database,
};

try {
result = await athenaExpress.query(myQuery);
console.log(result);
console.log('result ::: ', result);
} catch (error) {
throw new QueryError('Query could not be completed', error.message, {});
}
Expand All @@ -44,12 +44,29 @@ export default class Athena implements QueryService {
status: 'ok',
};
}
async getConnection(sourceOptions: SourceOptions, queryOptions?: QueryOptions): Promise<any> {
const AthenaExpress = require('athena-express'),
AWS = require('aws-sdk'),
awsCredentials = {
region: sourceOptions.region,
accessKeyId: sourceOptions.access_key,
secretAccessKey: sourceOptions.secret_key,
};

async getConnection(sourceOptions: SourceOptions, options?: object): Promise<any> {
const credentials = {
accessKeyId: sourceOptions['access_key'],
secretAccessKey: sourceOptions['secret_key'],
AWS.config.update(awsCredentials);
const athenaExpress = new AthenaExpress(awsCredentials);
const myQuery = {
sql: 'SELECT * FROM Customers',
db: sourceOptions.database,
};
return { region: sourceOptions['region'], credentials };
const client = athenaExpress
.query(myQuery)
.then((results) => {
return results;
})
.catch((error) => {
throw new Error('Invalid credentials');
});
return { client };
}
}
12 changes: 11 additions & 1 deletion plugins/packages/athena/lib/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
}
},
"defaults": {
"database": {
"value": ""
},
"output_location": {
"value": ""
},
Expand All @@ -43,6 +46,12 @@
}
},
"properties": {
"database": {
"label": "Database",
"key": "database",
"type": "text",
"description": "Enter database name"
},
"output_location": {
"label": "S3 output location",
"key": "output_location",
Expand Down Expand Up @@ -174,6 +183,7 @@
"access_key",
"secret_key",
"region",
"output_location"
"output_location",
"database"
]
}
2 changes: 2 additions & 0 deletions plugins/packages/athena/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export type SourceOptions = {
access_key: string;
secret_key: string;
region: string;
output_location: string;
database: string;
};
export type QueryOptions = {
operation: string;
Expand Down

0 comments on commit 4fddb13

Please sign in to comment.