aoc_leaderbot_aws_lambda_impl

Crates.ioaoc_leaderbot_aws_lambda_impl
lib.rsaoc_leaderbot_aws_lambda_impl
version2.0.0
created_at2025-11-27 02:51:28.805737+00
updated_at2025-11-28 06:34:21.753216+00
descriptionImplementation of an Advent of Code leaderboard-watching bot running in AWS Lambda
homepagehttps://github.com/clechasseur/aoc_leaderbot/tree/main/aoc_leaderbot_aws_lambda_impl#readme
repositoryhttps://github.com/clechasseur/aoc_leaderbot
max_upload_size
id1952983
size166,682
Charles Lechasseur (clechasseur)

documentation

https://docs.rs/aoc_leaderbot_aws_lambda_impl/

README

aoc_leaderbot_aws_lambda_impl

CI codecov Security audit crates.io MSRV Contributor Covenant

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

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:

  1. Make sure to select the correct AWS region where the Lambda function was deployed
  2. Using the Search or a shortcut, navigate to the Lambda component
  3. Locate the bot's Lambda function and click to open it
  4. Under the Overview panel, select Configuration, then Permissions
  5. Right under Execution role, there should be the name of the IAM role with a link to open the role; click on that link
  6. Under Permission policies, click on Add permissions and select Create inline policy
  7. In the Service selector, choose DynamoDB
  8. Add the following permissions at a minimum:
    1. GetItem
    2. PutItem
    3. DescribeTable
  9. Under Resources, click on Add ARNs to add the ARN for the bot's DynamoDB table. The table name is aoc_leaderbot.
  10. Click Next to move to the next wizard page.
  11. Under Policy details, give the policy a name.
  12. 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.

Commit count: 251

cargo fmt