How to terminate instance from shell?

I’m trying to terminate my VM at the end of it’s run. shutdown -P 0 does nothing.

halt makes it go go unresponsive. However, the dashboard then shows it with an “alert” status, and it is available to be terminated, so I assume I’m still paying for it until I do so.

Is there a way to terminate the VM from its own shell?

From the instance’s terminal, you can only shut down the operating system but you cannot terminate the instance so that it stops being charged.

One workaround is the following and you can run it from any PC or even from inside the instance.

  1. Generate a Lambda Cloud API Key
    GPU Cloud Login | Lambda

  2. Run this command to list all your instances:
    Can I list my running instances from a command line? | Lambda Docs

curl -u API_KEY: https://cloud.lambdalabs.com/api/v1/instances \
-H "Content-Type: application/json"

output:

{
  "data": [
    {
      "id": "########",
      "ip": "##.##.##.##",
      "region": {
        "name": "us-west-1",
        "description": "California, USA"
      }
    }
  ]
}

Find your instance id (“########”) and delete it:

$ curl -u API_KEY: \
https://cloud.lambdalabs.com/api/v1/instance-operations/terminate \
-d '{"instance_ids":["########"]}'

I hope this helps!

1 Like