Skip to content

Instantly share code, notes, and snippets.

@crgimenes
Created September 5, 2021 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crgimenes/40d75dcf470e13eeb6ee6520cc8f6834 to your computer and use it in GitHub Desktop.
Save crgimenes/40d75dcf470e13eeb6ee6520cc8f6834 to your computer and use it in GitHub Desktop.
AWS Lambda to return client ip
package main
import (
"net/http"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
func handler(request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
if request.HTTPMethod == http.MethodGet {
return &events.APIGatewayProxyResponse{
StatusCode: http.StatusOK,
Body: request.Headers["x-nf-client-connection-ip"],
}, nil
}
return &events.APIGatewayProxyResponse{
StatusCode: http.StatusBadRequest,
Body: `bad request`,
}, nil
}
func main() {
// Make the handler available for Remote Procedure Call by AWS Lambda
lambda.Start(handler)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment