I'm working with a setup that involves Amplify, API Gateway, and Lambda. My Amplify app calls the API Gateway, which then triggers a Lambda function. Both Amplify and API Gateway are proxied through Cloudflare, but I'm having trouble getting the real user IP address in my Lambda logs. Instead, I only see a single, consistent IP address. I've checked the context and the event that API Gateway sends to Lambda, as well as the headers Cloudflare sets, but nothing seems to indicate the actual user IP. What could be causing this issue?
3 Answers
You might want to look at the `X-Forwarded-For` header of the incoming requests; that’s where the original user IP is usually stored. It often contains a list of IPs, so make sure you're checking the right one!
Don’t forget to check the API Gateway logs! Sometimes the IP you're seeing is actually coming from Cloudflare. It helps to verify what's being logged there.
Thanks! That made me realize server-side calls from Amplify were showing up instead of my IP.
Have you checked out this article? It might be a configuration issue on Cloudflare's end. Here’s the link: [Restoring Original Visitor IPs](https://developers.cloudflare.com/support/troubleshooting/restoring-visitor-ips/restoring-original-visitor-ips/)
I did check that article! Initially, it didn’t seem to help because everything looked fine, but I realized it was my own mistake after all.
I found two IPs there too, but they weren’t my actual IP. Still worth checking!