A Rust hobby project that mimics lottery system/4 digits. So what is 4 digits? 4-Digits
This project is using serverless framework approach to deploy Rust code to AWS Lambda platform.
- Generating 19 ramdom numbers that are between 0000 and 9999 and storing the results into db (mongoDB is my selection). Cron job is scheduled at 8pm everyday for result of the day.
- Getting result for the specific day from db through Rest HTTP API.
- Storing user's betting into db.
- Matching user's betting against result of the day and calculating winning prize.
- Need to implement proper error handling in this project.
- Need to change synchoronous approach to asynchoronous approach
- Having AWS account. And setup it for serverless deployment credential. Sample:
serverless config credentials --provider aws --key AKIAIOSFODNN7EXAMPLE --secret wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
- Having mongo Atlas account. And create a mongo Atlas project for this. Creating one db and one collection for the project.
Name of db: four_digits
Name of collection (only one is needed for now): draw_results
- Setup the database connection credential into AWS Secret Manager for following secret values:
db_username
: username of db user
db_password
: password of db user
db_host
: host url of db
- Change arn of the secret manager to arn of your own setup secret manager in serverless.yml file.
arn:aws:secretsmanager:*region*:*account-id*:secret:*resource-id*
- Perform serverless deployment command.
sudo sls deploy -v
Want to try out my deployed API? More than welcome to try:
Get Result:
curl --request POST \
--url https://doagccylv7.execute-api.us-east-1.amazonaws.com/dev/result \
--header 'content-type: application/json' \
--data '{
"date": "2020-05-18 00:00:00"
}'
I am still an ametuer Rustacean. Trying to learning Rust through some coding projects like this. This is my first try.