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

Missing @http headers #3091

Open
pr0g opened this issue Dec 22, 2024 · 4 comments
Open

Missing @http headers #3091

pr0g opened this issue Dec 22, 2024 · 4 comments
Labels
bug Something isn't working @http question Further information is requested transferred

Comments

@pr0g
Copy link

pr0g commented Dec 22, 2024

Amplify CLI Version

12.13.1

Question

I have been trying to use the @http resolver feature in Amplify with Transformer V2 by following the helpful docs here.

The request is working, but when I try and set custom headers I am not seeing them arrive at the endpoint I'm using.

In my case, I'm calling an Azure Function App Function. I have something in my schema.graphql file that looks like this:

type Query {
  myCustomHttpEndpoint(queryValue: String!): String
    @http(
      url: "https://my-custom-endpoint.azurewebsites.net/api/my_custom_endpoint"
      method: GET
      headers: [{ key: "ExampleHeaderKey", value: "ExampleHeaderValue" }]
    )
}

When I make the request, the function is called as expected, but the headers do not appear. I'm not 100% sure if they're not being set/sent by Amplify/AppSync, or they're being filtered by the Azure Function App.

I've turned monitoring on for the AppSync queries, and I don't see the new header key/value in the CloudWatch logs, I also don't see the header key/value in the Network tab of the Chrome Developer Tools when the request happens (this may be expected as the header is forwarded from AppSync to the HTTP endpoint).

If someone could please clarify when/where I might be able to view the headers on the AppSync side to check things are being sent correctly that would be incredibly helpful. It's possible I'm doing something wrong. If I can get a simple static header key/value to work, the aim is to then forward the authorization header to later use in the Azure Function App Function, something like this...

headers: [
    {
      key: "Authorization"
      value: "$context.request.headers.Authorization"
    }

But I didn't have much luck with that either, for full context the generated Query.myCustomHttpEndpoint.DataResolver.req.vtl file looks like this:

## [Start] Create request. **
#set( $headers = $utils.http.copyHeaders($ctx.request.headers) )
$util.qr($headers.put("accept-encoding", "application/json"))
$util.qr($headers.put("HeaderKey", "HeaderValue"))
{
  "version": "2018-05-29",
  "method": "GET",
  "resourcePath": "/api/my_custom_endpoint",
  "params": {
      "headers": $util.toJson($headers),
      "query": $util.toJson($ctx.args.query)
  }
}
## [End] Create request. **

Thank you very much for your help!

@pr0g pr0g added pending-triage question Further information is requested labels Dec 22, 2024
@ykethan
Copy link
Member

ykethan commented Dec 23, 2024

Hey,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂

@ykethan ykethan transferred this issue from aws-amplify/amplify-cli Dec 23, 2024
@AnilMaktala AnilMaktala added bug Something isn't working @http and removed pending-triage labels Dec 27, 2024
@AnilMaktala
Copy link
Member

Hey @pr0g, Thank you for bringing this up. I was able to reproduce the issue and have marked it as a bug for the team to investigate further.

@pr0g
Copy link
Author

pr0g commented Dec 27, 2024

Hi @AnilMaktala, no problem and thank you for following up.

While looking into this further, I was able to reproduce the problem by using the plain fetch API, so this might not specifically be an AppSync/Amplify issue. I think it might be necessary to use the HTTP OPTIONS method and handle this in the Azure Function App call explicitly to allow the headers to be sent to work around CORS (I still couldn't get it to work unfortunately, but I think it should be possible, this article has some more info).

I'll try and follow-up in the new year if I have any more luck, if you are able to find a similar problem and solution with Amplify please let me know! 😅

Thank you! (and happy holidays/new year!)

@bobbyu99
Copy link
Contributor

@pr0g I tried to repro this issue. I use AppSync API to send a GET request to API Gateway. From API Gateway's logs, I can see that it's receiving the headers from AppSync API as expected. I then try to send the request to Lambda, and I'm still unable to see the headers in Lambda's logs.

I suspect that some config of the API Gateway and/or Lambda (or Azure in your case) might not have let the headers pass through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working @http question Further information is requested transferred
Projects
None yet
Development

No branches or pull requests

4 participants