Below is my Input form from which, I want to send 2 inputted numbers as POST to AWS Lambda and want them to be added and I want the response of the added numbers to be displayed on the browser of the client. Let us keep in note, that we are using AWS CodeStar, so the Lambda part cannot be disturbed by us.
For this, I have written a code that goes:
app.js
var express = require('express');
var app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended:true}));
app.get("/", function(req, res) {
res.sendFile(__dirname+ "/index.html");
});
app.post("/", function(req, res) {
var a = Number(req.body.num1);
var b = Number(req.body.num2);
var c = a+b;
res.send("The sum is" + c);
});
// Export your Express configuration so that it can be consumed by the Lambda handler
module.exports = app
The Error which we are getting is : {"message":"Forbidden"}
index.html
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Calculator</title>
</head>
<body>
<form action="/" method="post">
<input type="text" name="num1" placeholder="Enter No. 1">
<input type="text" name="num2" placeholder="Enter No. 2">
<button type="submit" name="submit">CALCULATE</button>
</form>
</body>
</html>
index.js
'use strict';
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
const server = awsServerlessExpress.createServer(app)
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context);