Hello, My goal is connect Monday with lambda function. Lambda have to get some info via webhook and create new project in AWS. I’m trying to connect a board with lambda but getting failed(Failed to communicate with URL provided.).
My code for the lambda on python is:
import json
def lambda_handler(event, context):
# Print the entire ‘event’ object for debugging with double quotes
print(“Received event:”, json.dumps(event, indent=2))
# Extract the challenge value from the webhook event data
challenge = event['challenge']
# Create a dictionary with the challenge message using the extracted challenge value
response_message = {
"challenge": challenge
}
# Print the response message with double quotes
print("Response message:", json.dumps(response_message, indent=2, ensure_ascii=False))
return {
'statusCode': 200,
'body': json.dumps(response_message, ensure_ascii=False)
}
test show me the result:
"
Test Event Name
challenge
Function Logs
START RequestId: a5dd95bc-7a9a-4ba8-b2ea-57a48a1e2322 Version: $LATEST
Received event: {
“challenge”: “3eZbrw1aBm2rZgRNFdxV2595E9CY3gmdALWMmHkvFXO7tYXAYM8P”
}
Response message: {
“challenge”: “3eZbrw1aBm2rZgRNFdxV2595E9CY3gmdALWMmHkvFXO7tYXAYM8P”
}
"
Could you please help me understand what is the issue with integration with Monday.com.
Thank you in advance!
From the documentation for lambda function URLs, here is the full structure of the responses. No fields are required, and returning void returns a 200 with no body. Obviously not what you want here, but could be of use in some situations.
Thank you Cody. Lambda return as you told me. But when I got to the monday.com - webhooks - choose one - put Lambda URL (public accessible for the tests) - getting error "Failed to communicate " Uploading: Screenshot 2023-09-21 at 10.06.07.png…
iimport json
def lambda_handler(event, context):
# Print the entire 'event' object for debugging with double quotes
print("Received event:", json.dumps(event, indent=2))
# Extract the challenge value from the webhook event data
challenge = event['challenge']
# Create a dictionary with the challenge message using the extracted challenge value
response_message = {
"challenge": challenge
}
# Print the response message with double quotes
print("Response message:", json.dumps(response_message, indent=2, ensure_ascii=False))
return {
'statusCode': 200,
'body': json.dumps(response_message, ensure_ascii=False),
'headers': {
'Content-Type': 'application/json'
}
}
I know what the issue is, but I’m not going to directly tell you the answer because its learning time!
You’re testing your code with the “test” feature of the lambda console, correct? I suggest you check the cloudwatch logs when you test with the actual webhook. You may see the issue in your received event. Here is how to access them:
Look at the spoiler below for more once you check your logs!
Another hint is that function URL events are API Gateway Http API / apigateway-http-api-proxy events. In the console test setup, there are optional templates, you may want to check those out to get an idea of how different source’s events are structured.
I’d highly suggest you check out this project if you’re going to be doing python lambda functions regularly. Particularly look at Event Source Data Classes. In this case you want APIGatewayProxyEventV2. But you’ll want to look into AWS SAM for dealing with the dependencies better.