
Lambda function to answer the question: What's my IP?
When invoked via an AWS application level loadbalancer (ELB) the function will return the IP of the requesting client.
Prerequisites
- aws cli installed and configured with credentials and default region
- GNU Make
- Go >= 1.15.x
Install
- Create function execution role and note down the Arn of the role (e.g.
arn:aws:iam::123456789012:role/lambda-echoip
)
aws iam create-role --role-name lambda-echoip --assume-role-policy-document file://trust-policy.json`
- Build the deployment package
function.zip
:
make build
- Create function and note down the Function ARN (e.g.
arn:aws:lambda:eu-west-1:123456789012:function:lambda-echoip
):
aws lambda create-function --function-name lambda-echoip --runtime go1 --handler main --zip-file fileb://function.zip --role arn:aws:iam::123456789012:role/lambda-echoip`
- Create ELB target group for the function, and note down the TargetGroupArn (e.g.
arn:aws:elasticloadbalancing:eu-west-1:123456789012:targetgroup/lambda-echoip/7e8a3b1bb81b9338"
)
aws elbv2 create-target-group --name lambda-echoip --target-type lambda
- Grant ELB invocation rights on function:
aws lambda add-permission \
--function-name lambda-echoip \
--statement-id load-balancer \
--principal elasticloadbalancing.amazonaws.com \
--action lambda:InvokeFunction \
--source-arn arn:aws:elasticloadbalancing:eu-west-1:123456789012:targetgroup/lambda-echoip/7e8a3b1bb81b9338
- Register function as ELB target:
aws elbv2 register-targets \
--target-group-arn arn:aws:elasticloadbalancing:eu-west-1:123456789012:targetgroup/lambda-echoip/7e8a3b1bb81b9338 \
--targets Id=arn:aws:lambda:eu-west-1:123456789012:function:lambda-echoip
- Test function:
curl echoip-123456789.eu-west-1.elb.amazonaws.com
Development
make help
shows Makefile targets
make test
runs the tests
make deploy
will update an existing deployment with the new code