-
Notifications
You must be signed in to change notification settings - Fork 488
/
Copy pathListFunctionCommand.cs
73 lines (62 loc) · 2.31 KB
/
ListFunctionCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Amazon.Lambda;
using Amazon.Lambda.Model;
using Amazon.Lambda.Tools.Options;
namespace Amazon.Lambda.Tools.Commands
{
/// <summary>
/// List all the functions currently deployed to Lambda
/// </summary>
public class ListFunctionCommand : BaseCommand
{
public const string COMMAND_NAME = "list-functions";
public const string COMMAND_DESCRIPTION = "Command to list all your Lambda functions";
public static readonly IList<CommandOption> ListCommandOptions = BuildLineOptions(new List<CommandOption>
{
});
public ListFunctionCommand(IToolLogger logger, string workingDirectory, string[] args)
: base(logger, workingDirectory, ListCommandOptions, args)
{
}
public override async Task<bool> ExecuteAsync()
{
try
{
ListFunctionsRequest request = new ListFunctionsRequest();
ListFunctionsResponse response = null;
do
{
if (response != null)
request.Marker = response.NextMarker;
try
{
response = await this.LambdaClient.ListFunctionsAsync(request);
}
catch (Exception e)
{
throw new LambdaToolsException("Error listing Lambda functions: " + e.Message);
}
foreach (var function in response.Functions)
{
this.Logger.WriteLine((function.FunctionName.PadRight(40) + " (" + function.Runtime + ")").PadRight(10) + "\t" + function.Description);
}
} while (!string.IsNullOrEmpty(response.NextMarker));
}
catch (LambdaToolsException e)
{
this.Logger.WriteLine(e.Message);
return false;
}
catch (Exception e)
{
this.Logger.WriteLine($"Unknown error listing Lambda functions: {e.Message}");
this.Logger.WriteLine(e.StackTrace);
return false;
}
return true;
}
}
}