const querystring = require('querystring');
const docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'});
// Set this to the region you upload the Lambda function to.
AWS.config.region = 'us-east-1';
exports.handler = function(evt, context, callback) {
// Our raw request body will be in evt.body.
const params = querystring.parse(evt.body);
// Our field from the request.
const my_name = params['my-name'];
const my_address = params['my-address'];
const my_city = params['my-city'];
const my_state = params['my-state'];
const my_zipcode = params['my-zipcode'];
const my_phone = params['my-phone'];
const my_email = params['my-email'];
const my_special = params['my-special'];
var newrec = {
Item: {
name: my_name,
address: my_address,
city: my_city,
state: my_state,
zipcode: my_zipcode,
phone: my_phone,
email: my_email,
special: my_special
},
TableName: 'Customer'
};
docClient.put(newrec, function(err, data){
if (err){
callback(err, null);
}else{
const html = `<!DOCTYPE html><html>
<head>
<style>
body {
background-color: yellow;
font-family:Lucida Sans Unicode;
}
.center {
text-align: center;
color: Brown;
}
</style>
</head>
<h1>
</h1>
<br>
<br>
<br>
<h1>Your Customer Information</h1>
<br>
<br>
<p>Customer Name: ` + my_name + ` <br>
Address: ` + my_address + `<br>
City: ` + my_city + `<br>
State: ` + my_state + `<br>
Zip Code: ` + my_zipcode + `<br>
Phone; `+ my_phone + `<br>
Email: ` + my_email + `<br>
Specials `+ my_special + `</p>`;
callback(null, html);
}
});
}
// Generate HTML.
// const html = `<!DOCTYPE html><p>Customer Name: ` + my_name + ` <br> Customer Address:
// ` + my_address + `<br> Customer Phone `+ my_phone + `</p>`;
// const html = `<!DOCTYPE html><p>Customer Info ` + my_name + my_address + my_phone`</p>` ;
// Return HTML as the result.
================================================================
console.log('Starting Function');
const AWS = require('aws-sdk');
const querystring = require('querystring');
const docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'});
exports.handler = function(event, context, callback) {
const precs = querystring.parse(event.body);
// Our field from the request.
const my_name = precs['my-name'];
const my_bagel = precs['my-bagel'];
const my_number = precs['my-number'];
var params = {
TableName: 'Products',
Key: {
"name": my_number
},
ProjectionExpression: 'price'
};
docClient.get(params, function(err, data){
if (err){
console.log("error");
}else{
var bprice = data.Item;
console.log(bprice);
global.newprice = bprice.price;
console.log(global.newprice);
}
});
var newrec = {
Item: {
date: Date.now(),
name: my_name,
bagel: my_bagel,
amount: my_number,
oprice: global.newprice
},
TableName: 'Orders'
};
docClient.put(newrec, function(err, data){
if (err){
callback(err, null);
}else{
const html = `<!DOCTYPE html><p>Customer Name: ` + my_name + ` <br> Bagel Type :
` + my_bagel + `<br> Order Amt`+ my_number + `</p>`;
callback(null, html);
}
});
};
No comments:
Post a Comment