Congratulations, it’s a lambda

AWS Lambda with API Gateway

Requirements

Create Lambda Function

Boilerplate Test

Initial baby-lambda.js

exports.handler = async (event) => {    const months = 23;
const lbs = 100;
let message = "not a baby";
if(months < 24) {
message = lbs > 30?"it's a big baby":"it's a baby"
}
const response = {
statusCode: 200,
body: JSON.stringify({months, lbs, message}),
};
return response;
};

Setup AWS API Gateway

Create

Configure

Handle Variables

{
"lbs": "$input.params('lbs')",
"months": "$input.params('months')"
}

Deploy API Gateway

Update the baby-lambda.js function

Update Code

exports.handler = async (event) => {    const months = event.months;
const lbs = event.lbs;
if( !months || !lbs) {
return {
statusCode: 400,
body: JSON.stringify({error: "You must give a weight in lbs and age in months"}),
}
}
let message = "not a baby";
if(months < 24) {
message = lbs > 30?"it's a big baby":"it's a baby";
}
const response = {
statusCode: 200,
body: JSON.stringify({months, lbs, message}),
};
return response;
};

Update Test(s)

{
"lbs": 10,
"months": 19
}

Verify the API Gateway hits the Lambda function

Summary

--

--

Chief Builder at smarterverse

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store