This repository has been archived by the owner on Jan 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exports.js
56 lines (46 loc) · 1.84 KB
/
exports.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
exports.handler = function (event, context, callback) {
//format of event expected
//Copy
// {
// "resource": "Resource path",
// "path": "Path parameter",
// "httpMethod": "Incoming request's method name"
// "headers": {Incoming request headers}
// "queryStringParameters": {query string parameters }
// "pathParameters": {path parameters}
// "stageVariables": {Applicable stage variables}
// "requestContext": {Request context, including authorizer-returned key-value pairs}
// "body": "A JSON string of the request payload."
// "isBase64Encoded": "A boolean flag to indicate if the applicable request payload is Base64-encode"
// }
const idToRemove = event.queryStringParameters.id ;
const conn = "pg://dev:sunmicrordssp1der@micrords.ckeww55ptuog.eu-west-1.rds.amazonaws.com:5432/mydb";
const query = "DELETE FROM roles WHERE id='" + idToRemove + "';";
const { Client } = require('pg');
const clientParams = {
user: "dev",
password: "sunmicrordssp1der",
database: "mydb",
port: 5432,
host: "micrords.ckeww55ptuog.eu-west-1.rds.amazonaws.com"
};
const client = new Client(clientParams);
client.connect()
.then(() => {
client.query(query)
.then((res, err) => {
const response = {
"statusCode": 200,
"headers": {
"content-type": "application/json",
"Access-Control-Allow-Origin": "*"
},
"body": ""
};
client.end();
callback(null, response)
});
}).catch(() => {
callback(null, null)
})
};