Tuesday, 24 September 2019

AWS Serverless APIs & Apps


exports.handler = (event, context, callback) => {
    // TODO implement
    callback(null, {message: 'Hi, I\m Raj'});
};

-------------------------------------------------------------------------------------------------------------------

https://codepen.io/pen/?editors=0010

var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://ktl8ycz4w8.execute-api.us-east-1.amazonaws.com/dev/compare-yourself');
xhr.onreadystatechange = function(event) {
  console.log(event.target.response);
}
xhr.send();

---------------------------------------------------------------------------------------------------------------------

exports.handler = (event, context, callback) => {
    // TODO implement
    callback(null, event);
};

-----------------------------------------------------------------------------------------------------------

{
    "name": "Raj Kumar Gupta",
    "age": 28
}

------------------------------------------------------------------------------------------


exports.handler = (event, context, callback) => {
    // TODO implement
    callback(null, {headers: {'Control-Access-Allow-Origin': '*'}});
};

---------------------------------------------------------------------------------------------------------

exports.handler = (event, context, callback) => {
    console.log(event);
    callback(null, {headers: {'Control-Access-Allow-Origin': '*'}});
};

----------------------------------------------------------------------------------------------------


exports.handler = (event, context, callback) => {
    console.log(event);
    const age = event.personData.age;
    callback(null, age * 2);
};



------------------------------------------------------------------------------------------------------------------


{
    "personData": {
        "name": "Raj Kumar Gupta",
        "age": 28
    }

}

-----------------------------------------------------------------------------------------------

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "CompareData",
  "type": "object",
  "properties": {
    "age": {"type": "integer"},
    "height": {"type": "integer"},
    "income": {"type": "integer"}
  },
  "required": ["age", "height", "income"]
}

--------------------------------------------------------------------------------------

{
    "age": 28,
    "height": 72,
    "income": 2500
}

-------------------------------------------------------------------------------------------------------

exports.handler = (event, context, callback) => {
    // TODO implement
    callback(null, 'Deleted!');
};

-----------------------------------------------------------------------------------------------------------------


exports.handler = (event, context, callback) => {
    const type = event.type;
    if (type == 'all') {
        callback(null, 'All the data');
    } else if (type == 'single') {
        callback(null, 'Just my data');
    } else {
        callback(null, 'Hello from Lambda');
    } 
};

------------------------------------------------------------------------------------------------------

{
    "type": "$input.params('type')"


-----------------------------------------------------------


var xhr = new XMLHttpRequest();

xhr.open('POST', 'https://ktl8ycz4w8.execute-api.us-east-1.amazonaws.com/dev/compare-yourself');

xhr.onreadystatechange = function(event) {

  console.log(event.target.response);

}
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({age: 28, height: 72, income: 2500}));


-------------------------------------------------------------------------------------------------------------

var xhr = new XMLHttpRequest();

xhr.open('DELETE', 'https://ktl8ycz4w8.execute-api.us-east-1.amazonaws.com/dev/compare-yourself');

xhr.onreadystatechange = function(event) {

  console.log(event.target.response);

}
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send();


---------------------------------------------------------------------------------------------------------------

var xhr = new XMLHttpRequest();

xhr.open('GET', 'https://ktl8ycz4w8.execute-api.us-east-1.amazonaws.com/dev/all');

xhr.onreadystatechange = function(event) {

  console.log(event.target.response);

}
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send();

No comments:

Post a Comment