The first step is to create our function written in Python.
- Browse to (https://console.aws.amazon.com) and log in
- In the search bar enter "Lamba" and click on Lambda
- Click Create a function
- Author from scratch
- Function name: myIPFunction
- Runtime: latest version of Python
- Leave the rest at defaults, click Create function
- In the Code Source pane, replace the example function with one of the functions listed below
- lambda_test.py - easy to read simple version used in testing
- lambda_handler.py - full function used to build (www.ipgiraffe.com)
- Click Deploy
- Click Test
- For the test event
- Event name: Test
- Test Event JSON: test_event.json
- This provides a dummy IP address for the test to work
- Click Save
- Click Test and the test should succeed.
- For the test event
If you create a function URL and try to test it, you will get an internal server error. This is because our Lambda function depends on the API gateway to provide the IP address.
You can reduce your HTML to use less memory and transfer less bytes across the Internet using "minification" techniques. Trying pasting HTML code into the online minifier at (https://codebeautify.org/minify-html)
Similarly you can minify your Python code at (https://python-minifier.com/)
Using both, I created a 1460 byte version of the function, which started at 2.96 KB.
Instructions for Go Instructions for Node.js Instructions for Ruby Instructions for .NET 8 C# Instructions for Java Instructions for Rust