Hey guys, I need to get the “user IP” which consum...
# help
a
Hey guys, I need to get the “user IP” which consumes my API. My API it’s an API GW v2 which triggers a Lambda. Should I use
$context.identity.sourceIp
?
or how should I do it?
a
yep, that works. I use the same.
a
But did you configure the GW or something?
I’m checking the types and is not allowing me to use that param.
Due
Context
is
identity?: CognitoIdentity | undefined;
.
a
no, the Lambda automatically uses Lambda Proxy integration when we use the Api construct and so it works. Yep, there are typing issues, I define my own type for the request and then it works.
a
Nice.
Going to try.
a
The key that I use is
event.requestContext.http.sourceIp
, this variant works for those routes where cognito isn’t used. Otherwise
event.requestContext.identity.sourceIp
would be the key to use.
a
Oh nice.
I don’t have
http.sourceIp
in my type neither.
a
haha yep. 😂
a
So you added it?
a
yep, extended the interface and added it.
a
Thanks.
t
Can you use
identity!.sourceIp
?
a
I dont have identity.
t
ah nvm
a
It’s just a public endpoint.
@thdxr might be possible to read these attributes from the HTTP Proxy gateway?
Sounds like should be possible.
But maybe is not implemented.
Would be nice to access the EVENT.