Skip to content

Cognito APIs aren't proxied correctly #7240

@ofiesh

Description

@ofiesh

I tried this:

When deployed to AWS, the APIs modified by the cognito winglib fail when submitting a json body and are missing a mapping for the response.

  1. The request integration doesn't work for json bodies:

https://github.com/winglang/winglibs/blob/main/cognito/platform/tfaws.w#L188

When deployed to AWS, submitting a json body errors on the integration request mapping:

Could not parse request body into json: Could not parse payload into json:

The mapping has:
\"body\" : \"$input.body\",

but it should be unquoted (I tested by manually modifying in AWS, it worked):
\"body\" : $input.body,

  1. Responses are pass through:

When using proxy integrations for api gateway, the cloud.ApiResponse allows you to return a status and a body as fields in the struct.

Because cognito does not use the proxy integration (it uses a custom mapping for the request), the response is a pass through. When returning a cloud.apiResponse, the client response gets the raw struct:

image

This happened:

When submitting a json body to a cognito modified api:

{
    "message": "Could not parse request body into json: Could not parse payload into json: Unexpected character (\'n\' (code 110)): was expecting comma to separate Object entries\n at [Source: (byte[])\"\n    {\n      \"httpMethod\": \"POST\",\n      \"path\": \"/teams\",\n      \"body\" : \"{\"name\": \"bar\"}\",\n      \"headers\": {\n        \"x-wing-cognitoIdentityId\": \"\",\n        \"x-wing-cognitoAuthenticationProvider\": \"\",\n                \"Accept\": \"*\\/*\"\n        ,                \"Accept-Encoding\": \"gzip, deflate, br\"\n        ,                \"Authorization\": \"Bearer ... \"[truncated 2300 bytes]; line: 5, column: 20]"
}

When receiving a response from a cognito modified api:

{
    "statusCode": 200,
    "body": "[{\"id\":\"4f1ad4dc-e894-4cae-b7b1-97a72db4ae69\",\"name\":\"bar\"}]",
    "headers": {
        "Content-Type": "application/json"
    }
}

A response mapping template needs to be set up.

I expected this:

A successful lambda invocation

Is there a workaround?

Since the response is a pass through, the raw response can be returned instead of the cloud.ApiResponse

Anything else?

No response

Wing Version

0.85.39

Node.js Version

v22.12.0

Platform(s)

No response

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions