Skip to content

Instantly share code, notes, and snippets.

@charlypoly
Last active January 22, 2021 14:27
Show Gist options
  • Save charlypoly/1e6c30c574218ae27ca3d2e946432f97 to your computer and use it in GitHub Desktop.
Save charlypoly/1e6c30c574218ae27ca3d2e946432f97 to your computer and use it in GitHub Desktop.
exports.handler = (event, context, callback) => {
var AWS = require('aws-sdk');
AWS.config.update({region: 'eu-west-1'}); // configure region
const athena = new AWS.Athena();
athena.getNamedQuery({ NamedQueryId: '<your-query-id>' }, function(err, data) {
console.log('getNamedQuery', err, data);
if (!err) {
var params = {
QueryString: data.NamedQuery.QueryString,
ResultConfiguration: {
OutputLocation: 's3://<your-bucket-name>/<folder>',
},
QueryExecutionContext: {
Database: 'segment'
}
};
athena.startQueryExecution(params, function(err, data) {
console.log('startQueryExecution', err, data);
if (err) {
callback(err);
} else {
callback(null, 'query started');
}
});
} else {
callback(err);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment