4

I started looking into using AWS HTTP API as a single point of entry to some micro services running with ECS.

One micro service has the following route internally on the server:

/sessions/{session_id}/topics

I define exactly the same route in my HTTP API and use CloudMap and a VPC Link to reach my ECS cluster. So far so good, the requests can reach the servers. The path is however not the same when it arrives. As per AWS documentation [1] it will prepend the stage name so that the request looks the following when it arrives:

/{stage_name}/sessions/{session_id}/topics

So I started to look into Parameter mappings so that I can change the path for the integration, but I cannot get it to work.

For requestParameters I want overwrite the path like below, but for some reason the original path with the stage variable is still there. If I just define overwrite:path as $request.path.sessionId I get only the ID as the path or if I write whatever string I want it will arrive as I define it. But when I mix the $request.path.sessionId and the other parts of the string it does not seem to work.

How do I format this correctly?

paths:
  /sessions/{sessionId}/topics:
    post:
      responses:
        default:
          description: "Default response for POST /sessions/{sessionId}/topics"
      x-amazon-apigateway-integration:
        requestParameters:
          overwrite:path: "/sessions/$request.path.sessionId/topics"
        payloadFormatVersion: "1.0"
        connectionId: (removed)
        type: "http_proxy"
        httpMethod: "POST"
        uri: (removed)
        connectionType: "VPC_LINK"
        timeoutInMillis: 30000

[1] https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-private.html

TheMan
  • 41
  • 2

2 Answers2

1

You can try to use parentheses. Formal notation instead of shorthand notation.

overwrite:path: "/sessions/${request.path.sessionId}/topics"

It worked well for me for complex mappings.

mapping template is a script expressed in Velocity Template Language (VTL)

vadiml
  • 41
  • 4
0

dont remove the uri and the connectionId and it will work for you. add only requestParameters: overwrite:path: "/sessions/$request.path.sessionId/topics"

oded
  • 161
  • 2
  • 8