Skip to main content

Hello World

It`s a simple function that returns a string.

exports.handler = async (event, context) => {

  console.log({event}, {context});

  const {body, httpMethod, queryStringParameters} = event;

  let name = "World";

  // if method GET
  if (httpMethod === "GET") {
    name = (queryStringParameters || {}).name || "World";
  }
  if (httpMethod === "POST") {
    name = (JSON.parse(body) || {}).name || "World";
  }

  return {
    statusCode: 200,
    body: JSON.stringify({
      message: `Hello ${name}!`,
    }),
  };

};

Check the source code on GitHub.

Test how it works

Edit this page