Created
September 5, 2021 12:58
-
-
Save crgimenes/40d75dcf470e13eeb6ee6520cc8f6834 to your computer and use it in GitHub Desktop.
AWS Lambda to return client ip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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