API Gateway Required Webhook Validation before receiving events

0

Hi, iam trying to achieve the following: An API Gateway resource should receive webhook notifications from an external service, transform the request to event bridge format and forward it directly to event bridge. I managed to create the configuration and mappings, so that it works when i post the webhook event data manually using postman.

My challenge is now that the "real" service iam using performs a validation check to the webhook listener before sending events. It sends a post request to the endpoint with a validation code in a header parameter and in order to activate this webhook subscription the validation code must be returned in the response.

I wonder if there is any configuration i can perform to do that validation step with API Gateway? In the sense of "if the requests contains a validation token, then create a response with the validation token, otherwise try the mapping and forward to event bridge" ?

Thank you in advance, Stefan

1개 답변
0

Hello Stefan,

Not sure if you can do it directly in the API Gateway,

but you could integrate a lambda function that validates the token and returns the token to the api gateway. If the token is present, forward the event to eventbridge.

Something like that ( + the eventbridge forwarding logic) :

def lambda_handler(event, context):
    headers = event.get('headers', {})
    validation_token = headers.get('Validation-Token')  

    if validation_token:
        # Validation token present, return it as a response
        return {
            'statusCode': 200,
            'headers': {
                'Content-Type': 'application/json'
            },
            'body': json.dumps({'validationToken': validation_token})
        }

Sincerely

Heiko

profile picture
HeikoMR
답변함 5달 전
profile picture
전문가
검토됨 한 달 전
  • Thank you Heiko. That is what i thought of. If it is a validation POST handle it by a Lambda otherwise transform and forward to event bridge. But it seems that there is no way to configure something like this in API Gateway - or i just havent found it :-(

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인