Service that manages and sends out User Fridge Notifications to users of FridgeFinder
User's of FridgeFinder are able to receive notification on status updates of a Community Fridge they are following
User's can Follow to a Community Fridge by going to a Fridge Profile and clicking on the Follow Button [TODO: implement follow button :)] - find one near you https://www.fridgefinder.app/browse
Currently User's can receive fridge notification via Email or SMS
- AWS CLI - Install the AWS CLI
- You DO NOT have to create an AWS account to use AWS CLI for this project, skip these steps if you don't want to create an AWS account
- AWS CLI looks for credentials when using it, but doesn't validate. So will need to set some fake one. But the region name matters, use any valid region name.
$ aws configure $ AWS Access Key ID: [ANYTHING YOU WANT] $ AWS Secret Access Key: [ANYTHING YOUR HEART DESIRES] $ Default region nam: us-east-1 $ Default output format [None]: (YOU CAN SKIP)
- SAM CLI - Install the SAM CLI
- You DO NOT need to create an aws account to use SAM CLI for this project, skip these steps if you don't want to create an aws account
- Note: if you are getting the following error:
runtime is not supportedwhen runningsam build --use-containermake sure your SAM CLI version is up to date
- Python 3 - Install Python 3
- Docker - Install Docker
Guide that was used: https://betterprogramming.pub/how-to-deploy-a-local-serverless-application-with-aws-sam-b7b314c3048c
Follow these steps to get Dynamodb running locally
-
Start a local DynamoDB service
$ docker compose up # OR if you want to run it in the background: $ docker compose up -d -
Create tables
$ ./scripts/create_local_dynamodb_tables.py
Confirm that the following requests work for you
cd Notification/sam build --use-containersam local invoke HelloWorldFunction --event events/event.json- response:
{"statusCode": 200, "body": "{\"message\": \"hello world\"}"}
- response:
sam local start-apicurl http://localhost:3000/hello- response:
{"message": "hello world"}
- response:
If it does yay, keep going 🤸♀️
These APIs are for interacting with individual user/fridge notification records
URL format: v1/users/{user_id}/notifications/{fridge_id}
Note: make sure your local dynamodb instance is running on docker. Follow instructions on Setup Local Database Connection
To test locally we use sam local invoke to mimick a cognito authorized request
-
POST Example
sam local invoke UserFridgeNotificationsFunction --event events/post_notification.json --parameter-overrides ParameterKey=Environment,ParameterValue=local ParameterKey=Stage,ParameterValue=dev --docker-network cfm-network -
PUT Example
sam local invoke UserFridgeNotificationsFunction --event events/put_notification.json --parameter-overrides ParameterKey=Environment,ParameterValue=local ParameterKey=Stage,ParameterValue=dev --docker-network cfm-network -
GET Example
sam local invoke UserFridgeNotificationsFunction --event events/get_notification.json --parameter-overrides ParameterKey=Environment,ParameterValue=local ParameterKey=Stage,ParameterValue=dev --docker-network cfm-network
- Create and activate a virtual environment from the project root:
python3 -m venv .venv
source .venv/bin/activate- Upgrade packaging tools and install the project in editable mode:
pip install -U pip setuptools wheel
pip install -e .- Install test dependencies:
pip install -r Notification/tests/requirements.txt- Run tests (unittest discovery):
python -m unittest discover -s Notification/tests/unit -t .Or run a single test file:
python -m unittest Notification.tests.unit.test_user_fridge_notifications_apiTo deactivate the environment when done:
deactivate- Build:
sam build --use-container - Deploy:
sam deploy --config-file samconfig.toml --config-env <ENVIRONMENT>
- edit CFMHostedZoneId in samconfig.toml
Only authenticated users are able to get or edit their notification preferences
curl --location --request GET 'https://notifications-api-dev.communityfridgefinder.com/v1/users/<USER_ID>/notifications/<FRIDGE_ID>' --header 'Authorization: <ID_TOKEN>'
curl --location --request <POST/PUT> 'https://notifications-api-dev.communityfridgefinder.com/v1/users/<USER_ID>/notifications/<FRIDGE_ID>'
--header 'Authorization: <ID_TOKEN>'
--header 'Content-Type: application/json'
--data '{
"contact_types_status": {"sms": "stop"},
"contact_types_preferences": {"sms": {"good": true, "dirty": true, "out_of_order": true, "not_at_location": true, "ghost": true, "food_level_0": false, "food_level_1": false, "food_level_2": true, "food_level_3": true, "cleaned": false}},
"contact_info": {"sms": "+18577048438"}
}'