Skip to content

Launches a Valheim Server on an EC2 Spot Instance with a Discord Bot

Notifications You must be signed in to change notification settings

samchungy/valheim-aws-spot-server

Repository files navigation

Valheim AWS Spot Instance Server

  • Launches a Valheim Server on an EC2 Spot Instance which backs up to S3 all from GitHub Actions.
  • Also creates a receiver for 2 slash commands on Discord - /valheim start and /valheim stop to start/stop the server.

Installation

  1. Clone Repo and commit to a private repo on Github.
  2. Adjust the config in Serverless.yml under Custom > Config. You will need to adjust
  • bucketName
  • region
  • serverName
  • instanceType (optional)
  1. Add the following secrets to GitHub Actions Secrets
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
DISCORD_PUBLIC_TOKEN
SERVER_PASSWORD # Valheim Server Password
SERVER_WEBHOOK # Discord Server Webhook URL
  1. Run the workflow. Profit.

  2. You can remove the Elastic IP option if you want to save a bit more money. Just delete all configuration with ElasticIP in it from the serverless.yml file. It will spit out the designated IP on every start.

Discord Slash Commands

You can setup Slash commands for your server here: https://discord.com/developers/docs/interactions/application-commands. Use the URL from the API Gateway path as the action endpoint for Discord. It will appear in the action's logs like this:

endpoints:
  POST - https://RANDOMID.execute-api.REGION.amazonaws.com/dev/interactions

Slash Command Discord API Sample Request Payload

{
    "name": "valheim",
    "description": "start or stop the valheim server",
    "options": [
        {
            "name": "start",
            "description": "Start the valheim server",
            "type": 1
        },
        {
            "name": "stop",
            "description": "Stop the valheim server",
            "type": 1
        }
    ],
    "default_permission": false
}

If you don't wish to use the Discord Slash Command integration you can invoke the start/stop Lambdas using the AWS CLI. eg.

aws lambda invoke \
    --function-name valheim-dev-start-server \
    --invocation-type Event \
    --payload '{}'

Releases

No releases published

Packages

No packages published