protected override async Task PerformActionAsync()

in src/Amazon.Lambda.Tools/Commands/InvokeFunctionCommand.cs [63:121]


        protected override async Task<bool> PerformActionAsync()
        {
            var invokeRequest = new InvokeRequest
            {
                FunctionName = this.GetStringValueOrDefault(this.FunctionName, LambdaDefinedCommandOptions.ARGUMENT_FUNCTION_NAME, true),
                LogType = LogType.Tail
            };

            if (!string.IsNullOrWhiteSpace(this.Payload))
            {
                if (File.Exists(this.Payload))
                {
                    Logger.WriteLine($"Reading {Path.GetFullPath(this.Payload)} as input to Lambda function");
                    invokeRequest.Payload = File.ReadAllText(this.Payload);
                }
                else
                {
                    invokeRequest.Payload = this.Payload.Trim();
                }

                // We should still check for empty payload in case it is read from a file.
                if (!string.IsNullOrEmpty(invokeRequest.Payload))
                {
                    if (invokeRequest.Payload[0] != '\"' && invokeRequest.Payload[0] != '{' && invokeRequest.Payload[0] != '[')
                    {
                        double d;
                        long l;
                        bool b;
                        if (!double.TryParse(invokeRequest.Payload, out d) && !long.TryParse(invokeRequest.Payload, out l) &&
                            !bool.TryParse(invokeRequest.Payload, out b))
                        {
                            invokeRequest.Payload = "\"" + invokeRequest.Payload + "\"";
                        }
                    }
                }
            }

            InvokeResponse response;
            try
            {
                await LambdaUtilities.WaitTillFunctionAvailableAsync(this.Logger, this.LambdaClient, invokeRequest.FunctionName);
                response = await this.LambdaClient.InvokeAsync(invokeRequest);
            }
            catch(Exception e)
            {
                throw new LambdaToolsException("Error invoking Lambda function: " + e.Message, LambdaToolsException.LambdaErrorCode.LambdaInvokeFunction, e);
            }

            this.Logger.WriteLine("Payload:");

            PrintPayload(response);

            this.Logger.WriteLine("");
            this.Logger.WriteLine("Log Tail:");
            var log = System.Text.UTF8Encoding.UTF8.GetString(Convert.FromBase64String(response.LogResult));
            this.Logger.WriteLine(log);

            return true;
        }