Python code to pull recent status messages from status.lol and generate javascript that can be embedded
- Python 100%
|
|
||
|---|---|---|
| lambda_function.py | ||
| README.md | ||
statuslog-to-javascript
Python code to pull recent status messages from status.lol and generate javascript that can be embedded
Prerequisite
- A Lambda Layer that includes the Python Requests package, which is not natively available in Lamdba.
(Rough) Instructions for Use
- Create Lambda Function and insert code (
lambda_handler.py) - Update
OMGLOL_USERNAMEinlambda_handler()function - Add Requests Lambda Layer to Lambda Function
- Configure Lambda Function
a. Increase maximum runtime from the default 3 seconds (I have mine set to 12 seconds)
b. Make sure the Function URL is enabled and public; configure to accept
GETrequests only.
Usage
Embed the following in your HTML (e.g. on your /now page):
<script src="https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.lambda-url.us-east-2.on.aws/?days=10&statuses=20"></script>
The following parameters are allowed (in order of precedence):
hours=HOURSReturn statuses for the lastHOURShoursdays=DAYSReturn statuses for the lastDAYSdaysweeks=WEEKSReturn statuses for the lastWEEKSweeks (computed asDAYS=WEEKS× 7)months=MONTHSReturn statuses for the lastMONTHSmonths (computed asDAYS=MONTHS× 30.4)years=YEARSReturn statuses for the lastYEARSyears (computed asDAYS=YEARS× 365.25)
You can also specify a maximum number of statuses to return:
statuses=MAX(default=1)
How to Create the Requests Lambda Layer
I’m doing this on a Mac running Tahoe 26.3.1 (a).
- Create a Python environment for your target version. (I’m using Anaconda distro.)
conda create -n python_3_13 python=3.13
- Activate the new envirnment
conda activate python_3_13
- Create a working directory. Make sure the version number matches.
mkdir -p requests-layer/python/lib/python3.13/site-packages
- Install packages to the target directory. This will install non-binary versions of the Requests package, as well as several dependencies.
pip install requests --target requests-layer/python/lib/python3.13/site-packages --no-binary=:all:
- Package the contents into a ZIP file. Note the change directory in the first step. This ensures that the
pythondirectory is the first one in the path. That’s important for the Lambda Layer to work correctly. I also like to include a version number that matches the Layer version.
cd requests-layer
zip -r ../requests-layer-v3.zip ./python
Now you’re all set to create your Lambda Layer and add it to your Lambda Function(s).