How can I get the user’s real IP address with Amplify, API Gateway, and Lambda?

0
0
Asked By CreativeNinja99 On

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

Answered By CuriousDev74 On

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!

HelpfulCoder21 -

I found two IPs there too, but they weren’t my actual IP. Still worth checking!

Answered By TechGuru88 On

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.

CreativeNinja99 -

Thanks! That made me realize server-side calls from Amplify were showing up instead of my IP.

Answered By CloudflareNerd On

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/)

CreativeNinja99 -

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.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.