You can quickly run this app using Poetry.
pip install poetry
Then install packages:
poetry install --sync
You need a database setup for job_post_counts_scraper. This app works only with PostgreSQL database so Sqlite3 database won't work. Please prepare local PostgreSQL database like this
To run this app in production, you need to provide some environment variables like the following:
DB_USER=your_db_app_user_name \
DB_PASS=your_db_app_user_pass \
DB_HOST=your_db_host_name \
DB_PORT=your_db_port \
DB_NAME=your_db_name \
poetry run python src/app/lambda_function.py
To run the tests, run:
poetry run python -m pytest -s
You can omit -s
if you don't need prints.
FUNCTION_ENVIRONMENT
needs to be aws_lambda
.
AWS_RDS_ENDPOINT
has to tell your RDS database endpoint.
AWS_DB_SECRETS_NAME
has to tell your AWS Secrets Manager secrets name which contains username
/ password
/ port
/ dbname
of your target database.
I set up GitHub actions workflow to package and deploy this to AWS lambda, but you can also do it manually with the following commands if your environment is Linux;
Packaging needs to be executed on Linux to make psycopg2 work on the Lambda environment. See https://stackoverflow.com/a/46366104
rm -rf dist && mkdir -p dist/lambda-package
rm -rf .venv && poetry install --only main --sync
cp -r .venv/lib/python*/site-packages/* dist/lambda-package/
cp -r src/app/* dist/lambda-package/
rm -rf dist/lambda-package/**/__pycache__
cd dist/lambda-package
zip -r ../lambda.zip .
cd ../..
The above makes your packages only for production (which means excluding packages for development purposes such as testing). So you'd better revert it to the development environment ASAP with the below:
rm -rf .venv && poetry install --sync