-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
83 lines (71 loc) · 2.43 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
try {
require("dotenv").config();
} catch (e) {}
const express = require("express");
const bodyParser = require("body-parser");
const AWS = require("aws-sdk");
const app = express();
const port = process.env.PORT || 3000;
// Set up view engine
app.set("view engine", "ejs");
// Use body-parser
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use("/static", express.static(__dirname + "/node_modules/bootstrap/dist"));
// Initialize AWS SDK with your AWS credentials
AWS.config.update({
region: process.env.AWS_REGION,
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
});
// Create AWS DataPipeline client
const dataPipeline = new AWS.DataPipeline();
// Route for the home page
app.get("/", async (req, res) => {
// Get the list of pipelines
const pipelines = await dataPipeline.listPipelines().promise();
res.render("index", { pipelines: pipelines.pipelineIdList });
});
// Route for viewing a specific pipeline
app.get("/pipeline/:id", async (req, res) => {
const pipelineId = req.params.id;
const pipelineDefinition = await dataPipeline
.getPipelineDefinition({ pipelineId })
.promise();
res.render("pipeline", { pipelineId, pipelineDefinition });
});
// Route for editing a specific pipeline
app.post("/pipeline/:id", async (req, res) => {
const pipelineId = req.params.id;
const pipelineObjects = req.body.pipelineObjects;
await dataPipeline
.putPipelineDefinition({ pipelineId, pipelineObjects })
.promise();
res.redirect(`/pipeline/${pipelineId}`);
});
// Route for creating a new pipeline
app.post("/create", async (req, res) => {
const pipelineName = req.body.pipelineName;
const newPipeline = await dataPipeline
.createPipeline({ name: pipelineName, uniqueId: Date.now().toString() })
.promise();
res.redirect(`/pipeline/${newPipeline.pipelineId}`);
});
// Route for deleting a pipeline
app.post("/delete", async (req, res) => {
const pipelineId = req.body.pipelineId;
await dataPipeline.deletePipeline({ pipelineId }).promise();
res.redirect("/");
});
// Route for getting pipeline status
app.get("/status/:id", async (req, res) => {
const pipelineId = req.params.id;
const pipelineStatus = await dataPipeline
.describePipelines({ pipelineIds: [pipelineId] })
.promise();
res.json(pipelineStatus);
});
// Start the server
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});