- Notifications
You must be signed in to change notification settings - Fork0
A .NET library for interacting with the Lambda API
License
patchoulish/lambda-dotnet
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A .NET library for interacting with theLambda API.
Install the library viaNuGet:
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 viaNuGet:
dotnet add package lambda-dotnet-dependencyinjection
- Obtain an API key from theLambda 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:
varlambdaCloud=newLambdaCloudService("YOUR_LAMBDA_API_KEY");
Use an existingHttpClient
, ensuring thatBaseAddress
and anAuthorization
header have been set:
varhttpClient=newHttpClient{BaseAddress=newUri("https://cloud.lambdalabs.com/api/v1/"),Timeout=TimeSpan.FromSeconds(5)};httpClient.DefaultRequestHeaders.Authorization=newAuthenticationHeaderValue("Bearer","YOUR_LAMBDA_API_KEY");varlambdaCloud=newLambdaCloudService(httpClient);
If you've installed the appropriate extension library.
- Register
LambdaCloudService
with your dependency container:
services.AddLambdaCloudHttpClient(options=>{options.BaseUrl=newUri("https://cloud.lambdalabs.com/api/v1/");options.ApiKey="YOUR_LAMBDA_API_KEY";});
- Inject
ILambdaCloudService
where needed:
publicclassMyClass{privatereadonlyILambdaCloudServicelambdaCloud;publicMyClass(ILambdaCloudServicelambdaCloud){this.lambdaCloud=lambdaCloud;}}
To list your running instances:
varinstances=awaitlambdaCloud.Instances.GetAllAsync();
To retrieve the details of an instance:
varinstanceId= ...var instance=awaitlambdaCloud.Instances.GetAsync(instanceId);
To list the instance types offered by Lambda Cloud and explore their specs as well as their region-specific availability:
varinstanceTypeAvailabilities=lambdaCloud.Instances.GetAllTypeAvailabilityAsync();varinstanceTypesToLaunch=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:
varoptions=newLambdaCloudInstanceLaunchOptions(){RegionName="us-east-1",TypeName="gpu_1x_a100_sxm4",KeyNames=["my-ssh-key"],Quantity=1}varinstance=awaitlambdaCloud.Instances.LaunchAsync(options);
To restart one or more running instances:
varinstances= ...var options=newLambdaCloudInstanceRestartOptions(){Ids=[instances[0].Id,instances[1].Id, ...]}var restartedInstances=awaitlambdaCloud.RestartAsync(options);
To terminate one or more running instances:
varinstances= ...var options=newLambdaCloudInstanceTerminateOptions(){Ids=[instances[0].Id,instances[1].Id, ...]}var terminatedInstances=awaitlambdaCloud.TerminateAsync(options);
To list the SSH keys saved in your account:
varkeys=awaitlambdaCloud.Keys.GetAllAsync();
To add an existing SSH key to your account:
varoptions=newLambdaCloudKeyAddOrGenerateOptions(){Name="my-existing-key",PublicKey="<YOUR_PUBLIC_KEY_HERE>"}varkey=awaitlambdaCloud.Keys.AddOrGenerateAsync(options);
To generate a new SSH key pair:
varoptions=newLambdaCloudKeyAddOrGenerateOptions(){Name="my-generated-key",PublicKey=null// Omit the public key}varkey=awaitlambdaCloud.Keys.AddOrGenerateAsync(options);// Make sure to save the private key returned to you.awaitFile.WriteAllTextAsync("my-generated-key.pem",key.PrivateKey);
To delete an SSH key from your account:
varkey= ...awaitlambdaCloud.Keys.DeleteAsync(key.Id);
To list your persistent storage filesystems:
varfilesystems=awaitlambdaCloud.Filesystems.GetAllAsync();
Refer to theUsage 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'sCloud API documentation as well as theirCloud 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. Seelicense.txt
for full details.
About
A .NET library for interacting with the Lambda API
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.