├── .github └── workflows │ ├── create.yml │ └── list_types.yml ├── README.md ├── actions.png ├── create_instance.py └── list_types.sh /.github/workflows/create.yml: -------------------------------------------------------------------------------- 1 | name: Create Instance 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | instance_type: 7 | description: 'Type of the instance' 8 | required: true 9 | type: choice 10 | options: # run list_types.sh to get the list of available instance types 11 | - "gpu_8x_h100_sxm5" 12 | - "gpu_1x_h100_pcie" 13 | - "gpu_8x_a100_80gb_sxm4" 14 | - "gpu_1x_a10" 15 | - "gpu_1x_rtx6000" 16 | - "gpu_1x_a100" 17 | - "gpu_1x_a100_sxm4" 18 | - "gpu_2x_a100" 19 | - "gpu_4x_a100" 20 | - "gpu_8x_a100" 21 | - "gpu_1x_a6000" 22 | - "gpu_2x_a6000" 23 | - "gpu_4x_a6000" 24 | - "gpu_8x_v100" 25 | 26 | jobs: 27 | create_instance: 28 | runs-on: ubuntu-latest 29 | steps: 30 | - name: Checkout code 31 | uses: actions/checkout@v3 32 | 33 | - name: Set up Python 34 | uses: actions/setup-python@v3 35 | 36 | - name: Install dependencies 37 | run: | 38 | pip install lambdacloud 39 | 40 | - name: Execute script 41 | env: 42 | LAMBDA_CLOUD_TOKEN: ${{ secrets.LAMBDA_CLOUD_TOKEN }} 43 | run: | 44 | python create_instance.py --instance_type ${{ github.event.inputs.instance_type }} 45 | -------------------------------------------------------------------------------- /.github/workflows/list_types.yml: -------------------------------------------------------------------------------- 1 | name: List Instance Types 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | query_lambda: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout code 11 | uses: actions/checkout@v2 12 | 13 | - name: See types 14 | run: | 15 | ./list_types.sh 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Get Lambda Instances 2 | 3 | Use GitHub Actions to get the lambda cloud instances you want. 4 | 5 | ## Setup 6 | 7 | 1. Fork this repo 8 | 9 | 2. Add your Lambda [cloud token](https://cloud.lambdalabs.com/api-keys) as a new [repository secret](https://github.com/hamelsmu/get-lambda/settings/secrets/actions) named `LAMBDA_CLOUD_TOKEN`. You should also set the `LAMBDA_CLOUD_TOKEN` environment variable locally. 10 | 11 | 3. Setup a new [ssh key in lambda](https://cloud.lambdalabs.com/ssh-keys) named `lambda-new`. And save the private key locally. You will need the private key to ssh into the instance after it is created. 12 | 13 | ## Run the workflow to get your Lambda instance 14 | 15 | 4. Go to your Actions tab and enable workflows if they aren't already enabled. Then click on the `Create Instance` workflow and select the kind of GPU that works for you: 16 | 17 | ![](actions.png) 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /actions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamelsmu/get-lambda/b1456601c1f8d388aa58af02f06977bc31212e38/actions.png -------------------------------------------------------------------------------- /create_instance.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | from lambdacloud import create_instance 3 | from lambdacloud import login 4 | import os 5 | import time 6 | 7 | def main(instance_type): 8 | sleep_time = 2 9 | login(token=os.getenv('LAMBDA_CLOUD_TOKEN')) 10 | 11 | while True: 12 | try: 13 | instance_id = create_instance(instance_type, ssh_key_names="lambda-new") 14 | print(f'Instance created with id: {instance_id}') 15 | break 16 | except: 17 | print(f'No {instance_type} found...sleeping for {sleep_time} seconds') 18 | time.sleep(sleep_time) 19 | 20 | if __name__ == "__main__": 21 | parser = argparse.ArgumentParser() 22 | parser.add_argument("--instance_type", type=str, required=True, help="Instance type to be created.") 23 | args = parser.parse_args() 24 | main(args.instance_type) 25 | -------------------------------------------------------------------------------- /list_types.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | curl -u ${LAMBDA_CLOUD_TOKEN}: \ 3 | https://cloud.lambdalabs.com/api/v1/instance-types \ 4 | | jq '.data[].instance_type.name' 5 | --------------------------------------------------------------------------------