This example demonstrates how to use a custom provider selector Lambda function to dynamically select providers and customize labels based on job characteristics.
- Repository-based routing: Route production repos to dedicated high-performance providers
- Job filtering: Skip runner provisioning for draft PRs
- Dynamic labels: Add branch name as a label dynamically
The provider selector Lambda function receives:
payload: The full GitHub webhook payloadproviders: Map of all available providers and their labelsdefaultProvider: The provider that would be selected by defaultdefaultLabels: The labels that would be used by default
The function returns:
provider: The node path of the provider to use (orundefinedto skip)labels: The labels to assign to the runner
- Production routing: If the repository name contains "prod" or "production", route to the production provider with LARGE compute type
- Draft PR filtering: Skip runner provisioning for branches starting with "draft/" or "wip/"
- Dynamic labels: For all other jobs, add the branch name as a label
⚡ Performance: The selector runs synchronously during webhook processing. Keep it fast and efficient—the webhook has a 30-second timeout total.
-
Install dependencies:
pip install -r requirements.txt
-
Deploy the stack:
cdk deploy
-
Follow the setup instructions in the main README.md to configure GitHub integration.
-
Use the runners in your GitHub Actions workflows:
name: Production Build
on:
push:
branches: [main]
jobs:
build:
runs-on: [self-hosted, custom-runner, production]
steps:
- uses: actions/checkout@v5
- run: echo "Running on production provider"
name: Regular Build
on: push
jobs:
build:
runs-on: [self-hosted, custom-runner, default]
steps:
- uses: actions/checkout@v5
- run: echo "Running on default provider"You can customize the provider selector logic to:
- Route based on repository, branch, or workflow file
- Filter jobs based on time of day, day of week, or other criteria
- Add dynamic labels based on job metadata
- Implement cost optimization strategies
- Enforce security policies
To remove the stack:
cdk destroy