Search code examples
amazon-web-servicesaws-lambdaaws-api-gatewayreverse-proxyaws-amplify

AWS service as reverse proxy for request body


I am aware that there is API gateway, AWS amplify console for rewrites and redirects, however, I am looking for a service that can parse the request body and then act as a reverse proxy.

Problem at hand - We have payment gateways(PG) that allow us to configure only two webhooks(1 for production and 1 for UAT/staging), but we need another webhook for pre-production and hence thinking to use the second webhook slot as a reverse proxy server. And redirect an incoming request form a PG to an appropriate configured path after request body JSON parsing. JSON could be nested to any level.

For example:

{
"payment": {
"env": "staging"
     } 
}

**Configuration** - if $payment.env == "staging", redirect to https://example.com/staging/url 

Is there an AWS service that can allow to configure different paths for different request body?

Can AWS API gateway together with AWS lambda be used for this purpose? I could not find any code samples preferably in ruby or python. Can anyone please provide an example?


Solution

  • We were able to accomplish this after writing a custom code in AWS Lambda for each payment gateway(PG). Here's what we did:

    1. Except for production, we appended environment('uat', 'pre-prod', 'dev') to an existing unique attribute. And sent each payment request to the PG with this attribute.
    2. Each PG was configured with AWS lambda script callback URL.
    3. PG always sent the unique attribute along with the environment in the request body in each callback request.
    4. Lambda script parsed request body, requested an appropriate origin server and responded back to the PG.