forked from serverless-guru/templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (29 loc) · 996 Bytes
/
index.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
const secretKey = require('./common/loadSecretKey.js');
const faker = require('faker');
let mysql = null;
let secretKeyValues = null;
module.exports.handler = async (event) => {
if (!secretKeyValues)
secretKeyValues = await secretKey.getSecretData();
if (mysql == null) {
mysql = require('serverless-mysql')({
config: {
host: secretKeyValues.host,
// USE host as localhost if you are using a ssh tunnel to access the database.
// host: "localhost",
database: "sakila",
user: secretKeyValues.username,
password: secretKeyValues.password
}
});
}
const firstName = faker.name.firstName().replace(/[^a-zA-Z ]/g, "")
const lastName = faker.name.lastName().replace(/[^a-zA-Z ]/g, "")
if (event.Records) {
event.Records.forEach(async (record) => {
await mysql.query(`INSERT INTO actor (first_name, last_name) VALUES ('${firstName}', '${lastName}')`)
});
}
await mysql.end();
return 'done';
};