I need to proxy some calls from a front-end to back-end and I can't change their actual behaviours.

Here is an example to illustrate what I'm trying to achieve :

Client calls : https://myApiGateway/myProxy?whereTo=%2Ffoo%2Fv2%2Fbar%3Fbaz%3D1
Should be redirected to : https://partner.com/foo/v2/bar?baz=1

My first idea was to attach a lambda integration to the API Gateway endpoint where I could then decode and send the request easily but :

  1. I can't get it to work (high latency, request not ingested by the partner for some reason)
  2. I would prefer not to have to use a Lambda (extra latency, maintenance, cost etc.)

So browsing the AWS documentation, I figured it may be possible to use API Gateway HttpIntegration capabilities. In particular, I found some info regarding template mappings with the Apache VTL language.

Is is possible to actually achieve this ?

Any ideas ?

API Gateway proxy schema

On the AWS console, I can't find how to create and link a mapping to the Integration request > URL path parameters. Only basic mapping is proposed and no VTL script ? Integration request > URL path parameters

Ultimately I want to do this in Typescript CDK here is where I am at :

const proxyPartnerResource = restApi.root.addResource("myProxy", {
    defaultCorsPreflightOptions: {
        allowMethods: ["POST", "OPTIONS"],
    allowOrigins: apigw.Cors.ALL_ORIGINS,
    },
});

const integration = new apigw.HttpIntegration('https://partner.com', {
    httpMethod: 'POST',
    options: {
        requestTemplates: {
        'application/json': `{
            "path": "$util.urlDecode($input.params('whereTo'))"
        }`
    },
    },
});

proxyPartnerResource.addMethod('POST', integration, {
    requestModels: {
    'application/json': new apigw.Model(this, 'RequestModel', {
        restApi: restApi,
            schema: {},
    }),
    },
});
0

There are 0 answers