Progressing

This commit is contained in:
Benoy Bose 2025-01-09 17:02:18 +05:30
parent 16ceff2f15
commit 950a6b21e5
6 changed files with 1825 additions and 287 deletions

View File

@ -4,25 +4,26 @@
"name": "Node.js",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-22-bookworm",
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [3000],
"forwardPorts": [
3000
],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",
// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"codeium.codeium"
"codeium.codeium",
"postman.postman-for-vscode"
]
}
},
"features": {
"ghcr.io/devcontainers/features/aws-cli:1": {}
}
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
}

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
node_modules/
*.sqlite
.env

3
.vscode/launch.json vendored
View File

@ -13,6 +13,9 @@
],
"program": "${workspaceFolder}/server.js",
"cwd": "${workspaceFolder}",
"env": {
"AWS_DEFAULTS_MODE": "standard"
}
}
]
}

2061
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,10 @@
"license": "ISC",
"description": "",
"dependencies": {
"@aws-sdk/client-athena": "^3.699.0",
"@aws-sdk/client-s3": "^3.701.0",
"@aws-sdk/credential-providers": "^3.699.0",
"dotenv": "^16.4.5",
"fastify": "^5.1.0",
"fastify-plugin": "^5.0.1",
"sequelize": "^6.37.5",

View File

@ -1,14 +1,37 @@
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 + 1 AS result');
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) {