This is the backend git repository of team production.
- Create empty folder (in your github backend repo)
- Start windows powershell
- Navigate to folder
- npm init
- npm install mysql
- Create an index.js file in same folder
- Put following code in it (you can edit files with VS Code):
var mysql = require('mysql'); var config = require('./config.json'); var pool = mysql.createPool({ host : config.dbhost, user : config.dbuser, password : config.dbpassword, database : config.dbname }); exports.handler = (event, context, callback) => { //prevent timeout from waiting event loop context.callbackWaitsForEmptyEventLoop = false; pool.getConnection(function(err, connection) { // Use the connection connection.query('---YOUR_SQL_CODE----', function (error, results, fields) { // And done with the connection. connection.release(); // Handle error after the release. if (error) callback(error); else callback(null,results[0].chargen_nr); }); }); };
- Create config.json in your folder and put following code in it
{ "dbhost" : "----YOURHOST----", "dbname" : "----YOURDBNAME----", "dbuser" :"----YOURDBUSER----", "dbpassword" :"----YOURDBPASSWORD----" }
- Go in AWS Lambda and press "create function" in the right top corner. -> Set function name and node.js 14.x
- Zip all files in your folder
- Press "upload of .zip file" in the right top corner in AWS and upload your zipped files
- Go to API Gateway in your AWS account and create a new REST API.
- Create new ressource in your gateway with default properties.
- Create new method in your ressource. -> Integrationtype = Lambda function, no proxy configuration, lambda-region = eu-central-1 and choose your Lambda function.
- Don't forget to deploy after changes: Press button actions and deploy API.
- Julia Jillich
- David Krieg
- Evgeniya Puchkova
- Max Sauer