Skip to content

Latest commit

 

History

History
71 lines (55 loc) · 2.18 KB

README.md

File metadata and controls

71 lines (55 loc) · 2.18 KB

ESI 2021 - Production - Backend

This is the backend git repository of team production.

Demo

Get started

- Connect Lambda with MySql

  1. Create empty folder (in your github backend repo)
  2. Start windows powershell
  3. Navigate to folder
  4. npm init
  5. npm install mysql
  6. Create an index.js file in same folder
  7. 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); }); }); };

  8. Create config.json in your folder and put following code in it

    { "dbhost" : "----YOURHOST----", "dbname" : "----YOURDBNAME----", "dbuser" :"----YOURDBUSER----", "dbpassword" :"----YOURDBPASSWORD----" }

  9. Go in AWS Lambda and press "create function" in the right top corner. -> Set function name and node.js 14.x
  10. Zip all files in your folder
  11. Press "upload of .zip file" in the right top corner in AWS and upload your zipped files

- Connect REST API with a Lambda function

  1. Go to API Gateway in your AWS account and create a new REST API.
  2. Create new ressource in your gateway with default properties.
  3. Create new method in your ressource. -> Integrationtype = Lambda function, no proxy configuration, lambda-region = eu-central-1 and choose your Lambda function.
  4. Don't forget to deploy after changes: Press button actions and deploy API.

Authors

  • Julia Jillich
  • David Krieg
  • Evgeniya Puchkova
  • Max Sauer