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
Can't get ClientIP run in AWS Lambda with gin #3501
Comments
Do you have any trusted proxies set up? |
Hi @radurobot No, there are no any proxies set up. The gin application is lunched in AWS lambda and access the API via AWS API Gateway. If the gin application run in VM or PC, the Client IP can be obtained. |
Perhaps accepting this will solve the problem: #3520 |
Thanks for your message. |
the problem have be solved ? |
@Trygun I've seen your PR. Is there any way to bypass this issue with the current version of Gin? |
This is working for me in AWS just fine. You just need to configure it correctly. |
@duaneking If so, can you please elaborate, how? I've set X-Forwarded-For on API Gateway, but I obtain it through ctx.GetHeader call. |
that's because the getheader call is the wrong place to do it; its not working the way you want because that's the wrong place to configure it. Read the docs and the other bugs people have also filed after not reading the docs first. To get you started: #3336 Close this bug once that helps you, please. |
Hi @duaneking I add TrustedPlatform to my code: router := gin.New()
router.SetTrustedProxies(nil)
router.TrustedPlatform = "X-Forwarded-For"
r1 := router.Group("/users")
r1.POST("/login", ctl.login)
......another function......
func (ctl *UserController) login(c *gin.Context) {
log.Printf("client real IP:%s", c.ClientIP());
......
}
} This code run in AWS Lambda. Unfortunately, it can't get the real client IP, did I do something wrong? Thanks for your help. |
Its working for me correctly in production, and in the gin unit tests that pass before every release. As this is also something that's a part of the unit tests that pass for every release, the burden of proof is on you. If its not working for you then you need to check your entire config; if you configured the system you have deployed wrong, then you may need to use a different header or your sytem may be injecting the wrong ip. Thats a config issue, not a bug in gin. |
The code I have working in prod is effectively everything you have been given already:
But remember, you need to read the AWS docs and configure the api gateway correctly as well. It honestly sounds to me like you have a misconfigured API gateway, so check that. |
Can't get ClientIP run in AWS Lambda with gin
Description
Hi there,
I run a gin web application in AWS Lambda, but I can't get the client IP with gin function: context.ClientIP() or context.RemoteIP().
Very appreciate for anyone's help.
Code
call getIP() and get empty.
Environment
The text was updated successfully, but these errors were encountered: