Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cognito APIs aren't proxied correctly #7240

Open
ofiesh opened this issue Jan 9, 2025 · 0 comments
Open

Cognito APIs aren't proxied correctly #7240

ofiesh opened this issue Jan 9, 2025 · 0 comments
Labels
🐛 bug Something isn't working

Comments

@ofiesh
Copy link

ofiesh commented Jan 9, 2025

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.
@ofiesh ofiesh added the 🐛 bug Something isn't working label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant