A .NET library for interacting with the Lambda API.
Install the library via NuGet:
dotnet add package lambda-dotnet
Install optional library extensions for more functionality, depending on your use case.
Integrate lambda-dotnet and your DI container of choice. Install the extension library via NuGet:
dotnet add package lambda-dotnet-dependencyinjection
- Obtain an API key from the Lambda Cloud Dashboard (requires a Lambda account).
- Pass the API key into a new instance of the
LambdaCloudService
class or use a configuredHttpClient
if advanced configuration (e.g., proxies) is required. - Use the methods available on
LambdaCloudService
to interact with the Lambda Cloud API.
The library can be initialized in three ways:
Pass in your API key directly:
var lambdaCloud = new LambdaCloudService("YOUR_LAMBDA_API_KEY");
Use an existing HttpClient
, ensuring that BaseAddress
and an Authorization
header have been set:
var httpClient = new HttpClient
{
BaseAddress = new Uri("https://cloud.lambdalabs.com/api/v1/"),
Timeout = TimeSpan.FromSeconds(5)
};
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", "YOUR_LAMBDA_API_KEY");
var lambdaCloud = new LambdaCloudService(httpClient);
If you've installed the appropriate extension library.
- Register
LambdaCloudService
with your dependency container:
services.AddLambdaCloudHttpClient(options =>
{
options.BaseUrl = new Uri("https://cloud.lambdalabs.com/api/v1/");
options.ApiKey = "YOUR_LAMBDA_API_KEY";
});
- Inject
ILambdaCloudService
where needed:
public class MyClass
{
private readonly ILambdaCloudService lambdaCloud;
public MyClass(ILambdaCloudService lambdaCloud)
{
this.lambdaCloud = lambdaCloud;
}
}
To list your running instances:
var instances = await lambdaCloud.Instances.GetAllAsync();
To retrieve the details of an instance:
var instanceId = ...
var instance = await lambdaCloud.Instances.GetAsync(instanceId);
To list the instance types offered by Lambda Cloud and explore their specs as well as their region-specific availability:
var instanceTypeAvailabilities = lambdaCloud.Instances.GetAllTypeAvailabilityAsync();
var instanceTypesToLaunch = instanceTypeAvailabilities
.Where(x => x.Type.Specifications.GpuCount >= 4)
.Where(x => x.RegionsWithCapacity.Any())
.Select(x => x.Type)
You can launch an instance in the following way:
var options = new LambdaCloudInstanceLaunchOptions()
{
RegionName = "us-east-1",
TypeName = "gpu_1x_a100_sxm4",
KeyNames = [
"my-ssh-key"
],
Quantity = 1
}
var instance = await lambdaCloud.Instances.LaunchAsync(options);
To restart one or more running instances:
var instances = ...
var options = new LambdaCloudInstanceRestartOptions()
{
Ids = [ instances[0].Id, instances[1].Id, ... ]
}
var restartedInstances = await lambdaCloud.RestartAsync(options);
To terminate one or more running instances:
var instances = ...
var options = new LambdaCloudInstanceTerminateOptions()
{
Ids = [ instances[0].Id, instances[1].Id, ... ]
}
var terminatedInstances = await lambdaCloud.TerminateAsync(options);
To list the SSH keys saved in your account:
var keys = await lambdaCloud.Keys.GetAllAsync();
To add an existing SSH key to your account:
var options = new LambdaCloudKeyAddOrGenerateOptions()
{
Name = "my-existing-key",
PublicKey = "<YOUR_PUBLIC_KEY_HERE>"
}
var key = await lambdaCloud.Keys.AddOrGenerateAsync(options);
To generate a new SSH key pair:
var options =
new LambdaCloudKeyAddOrGenerateOptions()
{
Name = "my-generated-key",
PublicKey = null // Omit the public key
}
var key = await lambdaCloud.Keys.AddOrGenerateAsync(options);
// Make sure to save the private key returned to you.
await File.WriteAllTextAsync(
"my-generated-key.pem",
key.PrivateKey);
To delete an SSH key from your account:
var key = ...
await lambdaCloud.Keys.DeleteAsync(key.Id);
To list your persistent storage filesystems:
var filesystems = await lambdaCloud.Filesystems.GetAllAsync();
Refer to the Usage section above for a quick start, or consult the inline documentation while working in your IDE. For detailed information about the underlying API endpoints, parameters, and expected responses, refer to Lambda's Cloud API documentation as well as their Cloud API reference.
Contributions are welcome! To contribute, fork the repository, create a new branch, and submit a pull request with your changes. Please make sure all tests pass before submitting.
This project is licensed under the MIT license. See license.txt
for full details.