Alright, let’s get started.

Navigate to API Gateway from the console. It is located under “Networking and Content Delivery.”

Select REST, New API, and pick your API name to suit your needs. You can see below mine is named “Contact-Medium”

Then, create a new API using the REST protocol config:

Next, click the actions drop-down and select create method. Typically I would create a resource (corresponding to a noun endpoint like “/message” ), but since we only have one endpoint we will just add a POST method on the root.

Click on the green POST after clicking the check-mark, and select Lambda function as the integration type.

Go down to Lambda function and type in the name of your lambda function. In this case mine was named “send-telegram-message.” The field should auto-fill.

Click save, and you should get a popup to allow API Gateway to invoke your Lambda function. Click ok to accept.

You should now see a diagram with 6 boxes. The far left box “Client” has a Test button with a lightning bolt under it. Click it and you should see this page:

Let’s add our valid JSON payload that we used in the Lambda test case from the last article, changing the message to “from API Gateway”:



"name": "Test Name",

"email": "

"message": "Hello this is a test message from API Gateway"

} "name": "Test Name","email": " example-email@email.com ","message": "Hello this is a test message from API Gateway"

Click the test button and you should receive a Telegram message! To the right side you should also be shown the Response Body, Response Headers, and Logs.

What happens if you try and empty Request Body?

Can you spot what is wrong here?

…

Well, for one, there is a lot of data here the client should probably not be exposed to — like the stack trace. It is also poorly formatted, shouldn’t the field errors be parsed into JSON?

Is there anything else?

It took me a while to notice, but we are actually getting a 200 status code for an error! This would definitely cause some confusion on the client side when processing the response.