3 releases (stable)
Uses new Rust 2024
| 2.0.0 | Nov 28, 2025 |
|---|---|
| 1.0.0 | Nov 27, 2025 |
| 0.3.0 | Nov 27, 2025 |
#637 in Asynchronous
245KB
3.5K
SLoC
aoc_leaderbot_aws_lambda_impl
Implementation of aoc_leaderbot that runs as an AWS Lambda function.
aoc_leaderbot is a bot that can watch an Advent of Code private leaderboard for changes and report them to various channels.
Installing
Installing aoc_leaderbot_aws_lambda_impl requires building the project, deploying it to your AWS account and setting up permissions and (optionally) scheduling its execution.
Before deploying, make sure your environment contains credentials to access your AWS account; for more information, see this page.
A note about costs
This implementation of aoc_leaderbot uses serverless AWS services like Lambda and DynamoDB because at the time of this writing, those services were included in the AWS Free Tier.
In theory, running the bot every 15 minutes continuously should be well below service limits of the Free Tier. Please note however that this is not guaranteed as AWS costs can be affected by many things and change change over time. Before deploying the bot, make sure you are aware of possible hosting costs.
Prerequisites
- A clone of this project
- Rust 1.88 or newer (see DEVELOPMENT)
- just (see DEVELOPMENT)
- Cargo Lambda
Bot configuration
Create a file named .env at the project root and populate it with environment variables to configure the bot.
| Variable name | Content | Required? | Default value |
|---|---|---|---|
AOC_LEADERBOT_AWS_YEAR |
Year to monitor | ✓ | Current year |
AOC_LEADERBOT_AWS_LEADERBOARD_ID |
ID of leaderboard to monitor 1 | ✓ | - |
AOC_LEADERBOT_AWS_VIEW_KEY |
View key to access leaderboard's read-only link 2 | ✓ 3 | - |
AOC_LEADERBOT_AWS_SESSION_COOKIE |
Cookie of Advent of Code session to access the leaderboard | ✓ 3 | - |
SLACK_WEBHOOK_URL |
URL of Slack webhook where to report changes | ✓ | - |
SLACK_CHANNEL |
Slack channel where to report changes (without the #) |
✓ | - |
SLACK_LEADERBOARD_SORT_ORDER |
How to sort leaderboard members when reporting (see LeaderboardSortOrder) |
Stars |
1 : The leaderboard ID is the last part of the leaderboard's URL: https://adventofcode.com/{year}/leaderboard/private/view/{leaderboard_id}.
2 : If the leaderboard is accessible anonymously through a read-only link, the view key is passed as a query parameter: https://adventofcode.com/{year}/leaderboard/private/view/{leaderboard_id}?view_key={view_key}
3 : Either the VIEW_KEY or the SESSION_COOKIE must be set. If both are set, the VIEW_KEY is used.
Creating DynamoDB table
The bot stores leaderboard data in a DynamoDB table between runs. Before running the bot for the first time, create the table by running:
just prepare-dynamo
This will make sure that the table is created with the proper hash and range key configuration.
Building Lambda function
Build the Lambda function package so that it's ready for deployment by running:
just release=true build-lambda
Be patient as this can take a while the first time.
Deploying Lambda function
Once the Lambda function package is built, it can be deployed by running:
just deploy-lambda
Setting Up Permissions
Once the Lambda function is deployed, it needs to be given permission to read and write to the DynamoDB table. This can be done by editing the IAM role that has been created when the Lambda function was deployed. There are different ways of doing this; to do it via the AWS Management console:
- Make sure to select the correct AWS region where the Lambda function was deployed
- Using the Search or a shortcut, navigate to the Lambda component
- Locate the bot's Lambda function and click to open it
- Under the Overview panel, select Configuration, then Permissions
- Right under Execution role, there should be the name of the IAM role with a link to open the role; click on that link
- Under Permission policies, click on Add permissions and select Create inline policy
- In the Service selector, choose DynamoDB
- Add the following permissions at a minimum:
GetItemPutItemDescribeTable
- Under Resources, click on Add ARNs to add the ARN for the bot's DynamoDB table. The table name is
aoc_leaderbot. - Click Next to move to the next wizard page.
- Under Policy details, give the policy a name.
- Once ready, click on Create policy.
Please note that the AWS Management console might evolve over time and that the instructions above might become obsolete in the future; if in doubt, read the official documentation. It is also possible to attach these permissions to the role programmatically or via the AWS CLI.
Running the bot on a schedule
Up to now, the bot should be functional - you can test it by invoking the bot's Lambda function with a test event (an empty payload should do if all the environment variables were correctly set in you .env file prior to deploying the bot).
If you want to run the bot on a schedule, you can add a trigger to the bot's Lambda function.
Again, there are various possible trigger types; one is Amazon EventBridge.
Creating such a schedule is a bit outside the scope of this README, but you can peruse the EventBridge documentation for more information.
Updating
If ever a new version of the bot is released and you want to update your bot's Lambda function, you can simply build and deploy it again using the instructions above. This will deploy a new version of the Lambda function. (If the new version has breaking changes, be sure to read the instructions on how to upgrade before deployment.)
Contributing / Local development
For information about contributing to this project, see CONTRIBUTING. For information regarding local development, see DEVELOPMENT.
Dependencies
~15–34MB
~384K SLoC