41 lines
1.5 KiB
JavaScript
41 lines
1.5 KiB
JavaScript
import Fastify from "fastify";
|
|
import sequelizePlugin from "./plugins/sequelize.js";
|
|
import dotenv from "dotenv";
|
|
dotenv.config();
|
|
|
|
import { S3Client, ListBucketsCommand } from "@aws-sdk/client-s3";
|
|
const s3Client = new S3Client({ region: process.env.AWS_REGION, profile: 'default' });
|
|
const listCommand = new ListBucketsCommand({});
|
|
const response = await s3Client.send(listCommand);
|
|
const server = Fastify({ logger: true });
|
|
server.register(sequelizePlugin);
|
|
|
|
server.get("/", async (request, reply) => {
|
|
const [results, metadata] = await server.sequelize.query('SELECT 1 + 2 AS result');
|
|
return { hello: "world" };
|
|
});
|
|
|
|
const productQuery = `SELECT DISTINCT
|
|
line_item_resource_id AS resourceId,
|
|
line_item_product_code AS productCode,
|
|
line_item_usage_account_id AS accountId
|
|
FROM ${process.env.ATHENA_CU_TABLE};`;
|
|
|
|
import { AthenaClient, StartQueryExecutionCommand, GetQueryExecutionCommand, GetQueryResultsCommand } from "@aws-sdk/client-athena";
|
|
const athenaClient = new AthenaClient({ region: process.env.AWS_REGION, profile: 'default' });
|
|
|
|
const startQueryCommand = new StartQueryExecutionCommand({
|
|
QueryString: productQuery,
|
|
QueryExecutionContext: { Database: process.env.ATHENA_CU_DATABASE },
|
|
ResultConfiguration: { OutputLocation: process.env.ATHENA_OUTPUT_S3_BUCKET },
|
|
});
|
|
const startQueryResponse = await athenaClient.send(startQueryCommand);
|
|
console.log(startQueryResponse);
|
|
|
|
try {
|
|
await server.listen({ port: 3000 })
|
|
} catch (err) {
|
|
server.log.error(err)
|
|
process.exit(1)
|
|
}
|