Skip to content

Instantly share code, notes, and snippets.

@tarasowski
Created December 6, 2023 11:43
Show Gist options
  • Select an option

  • Save tarasowski/4ea4ea4895a7ed95e94f7e2243bc24cd to your computer and use it in GitHub Desktop.

Select an option

Save tarasowski/4ea4ea4895a7ed95e94f7e2243bc24cd to your computer and use it in GitHub Desktop.
median-price-calculator.mjs
export const medianPriceCalculator = async (event) => {
let region = event.region;
let medianPrice;
// Define median prices for US, CA and BR
const medianPrices = {
US: 320000.0,
CA: 240000.0,
BR: 260000.0,
};
// Check if the input region is valid and retrieve the corresponding median price
if (medianPrices.hasOwnProperty(region)) {
medianPrice = medianPrices[region];
} else {
medianPrice = medianPrices.US; // default to US median price if region is unknown
region = 'UNKNOWN REGION';
}
// Construct the response object
const response = {
statusCode: 200,
body: JSON.stringify({region: region, medianPrice: medianPrice}),
headers: {
'X-Powered-By': 'AWS API Gateway & Lambda'
},
isBase64Encoded: false
};
return response;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment