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

Add Cloudfront headers and prevent reverse proxy from stripping custom headers. #2459

Closed
Rafcin opened this issue Dec 17, 2021 · 8 comments
Closed
Labels
archived This issue has been locked. feature-request New feature or request

Comments

@Rafcin
Copy link

Rafcin commented Dec 17, 2021

Is your feature request related to a problem? Please describe.
Currently, you can't add additional CloudFront headers easily to a deployment. To add them you have to modify the serverless config during the build process and the Amplify team has to give access to the stripped headers if you use a custom domain.

Current way to modify the serverless config

  - appRoot: apps/example
    env:
    variables:
      #AMPLIFY_DIFF_DEPLOY: true
    frontend:
      phases:
        preBuild:
          commands:
            # Do pre-build stuff
        build:
          commands:
            # Run build and then copy over serverless
            - cp config/serverless.yml serverless.yml
      artifacts:
        baseDirectory: .next
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
APPID-HERE:
  component: '@sls-next/[email protected]'
  inputs:
    timeout:
      defaultLambda: 30
      apiLambda: 30
      imageLambda: 30
      regenerationLambda: 30
    cloudfront:
      defaults:
        forward:
          headers:
            - CloudFront-Is-Desktop-Viewer
            - CloudFront-Is-Mobile-Viewer
            - CloudFront-Is-Tablet-Viewer
            - CloudFront-Viewer-Country
            - CloudFront-Viewer-Latitude
            - CloudFront-Viewer-Longitude
            - CloudFront-Viewer-Time-Zone
            - CloudFront-Viewer-City
            - Authorization
    build:
      env:
        AMPLIFY_DIFF_DEPLOY: 'false'
        AMPLIFY_MONOREPO_APP_ROOT: apps/news

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-cloudfront-headers.html

Describe the solution you'd like
Ideally, a config option in the console would be nice. A dropdown similar to the Cloudfront behaviors dropdown would work.

The option to choose what is removed by the proxy would also be nice instead of having someone modify it. If someone plans to release 3 or 4 sites, they would need to contact the amplify team each time, therefore it would be easier to allow the users to modify it themselves per project.

@Rafcin Rafcin added the feature-request New feature or request label Dec 17, 2021
@mswezey23
Copy link

This is still a thing. Ouch.

They should allow the Cloudfront configs to be editable when using AWS Amplify. I'm running into this issue with GET requests being stripped of their headers when proxied through my AWS Amplify SPA. Guess I'll reach out to support to see what's possible.

@Rafcin
Copy link
Author

Rafcin commented Sep 12, 2022

@mswezey23 So there's going to be a beta of the new build system at some point in the near future (it's been up in the air atm, check the Next 12 support thread under the hosting repo) and possibly maybe hopefully that might include a solution to the header issue.

Definitely open a support ticket they can fix the header issue! Although quick note, I was denied last time I asked because they're looking for a better way to go about doing that (so I'm guessing the beta will.bave that feature) but if you have 1 app or something it's probably no big deal.

@fnavarrodev
Copy link

I don't think they added cloudfront headers in the new releases but I'm gonna give it a try today and see.

@fnavarrodev
Copy link

I have good news and bad news. There's one header cloudfront-viewer-country now how do we get cloudfront-viewer-country-region?

@p00000001
Copy link

This is still a thing. Ouch.

They should allow the Cloudfront configs to be editable when using AWS Amplify. I'm running into this issue with GET requests being stripped of their headers when proxied through my AWS Amplify SPA. Guess I'll reach out to support to see what's possible.

@mswezey23 Did AWS Support ever offer you a solution to keep the original request headers? I'm deploying a React/Next.js app in AWS Amplify and need access to the user-agent header, which is always set to Amazon Cloudfront by Amplify.

@calavera
Copy link
Contributor

This feature has just been supported with our latest launch! I'm closing this issue as it should be resolved now.

Check out the details here: https://aws.amazon.com/blogs/mobile/cdn-caching-improvements-for-better-app-performance-with-aws-amplify-hosting/

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Copy link

This issue has been automatically locked.

@github-actions github-actions bot added the archived This issue has been locked. label Aug 13, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived This issue has been locked. feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants