public String CleanupFromReport(EBSCleanupInput input, ILambdaContext context)
        {
            AmazonEC2Client ec2Client = new AmazonEC2Client();

            String[] lines = new AWSCommon().GetS3ContextAsText(input.BucketName, input.Key).Split("\n".ToCharArray());
            List <Task <DeleteSnapshotResponse> > deleteTasks = new List <Task <DeleteSnapshotResponse> >();
            int index = 0;

            foreach (String line in lines)
            {
                if (input.StartIndex > index)
                {
                    index++;
                    continue;
                }

                //check if lambda timeout is near, if so invoke function recursively
                if (context.RemainingTime.Seconds < 20)
                {
                    context.Logger.LogLine("Lambda timouet near end, starting Lambda recursivly...");
                    var lambdaClient = new Amazon.Lambda.AmazonLambdaClient();
                    input.StartIndex = index;
                    lambdaClient.InvokeAsync(new Amazon.Lambda.Model.InvokeRequest()
                    {
                        InvocationType = Amazon.Lambda.InvocationType.Event,
                        FunctionName   = context.FunctionName,
                        Payload        = JsonConvert.SerializeObject(input)
                    }).Wait();
                    return("Started recursively with index=" + index);
                }

                string[] cells = line.Split(',');
                if (cells.Length > 1)
                {
                    string snapshotId = cells[1];
                    //check if snapshot id in appropriate format
                    if (new Regex("snap-(.*)").Match(snapshotId).Success)
                    {
                        context.Logger.LogLine($"CSV-L#{index} Deleting snapshot {snapshotId}..");
                        try {
                            var response = (ec2Client.DeleteSnapshotAsync(new DeleteSnapshotRequest()
                            {
                                SnapshotId = snapshotId
                            }));
                            response.Wait();
                        }catch (Exception ex) {
                            context.Logger.LogLine($"failed deleting snapshot {snapshotId}:\n{ex}");
                        }
                    }
                    else
                    {
                        context.Logger.LogLine($"Snapshot id {snapshotId} not in snap-xx format");
                    }
                }
                index++;
            }

            return("OK");
        }
        public async void WriteRecord(string fname, string nick, int age, string gender)
        {
            //point the lambda call to the right location endpoint
            Amazon.RegionEndpoint region = Amazon.RegionEndpoint.USEast1;

            //credentials
            var awsCredentials = new Amazon.Runtime.BasicAWSCredentials(Auth.AWSKey, Auth.AWSSecret);

            try
            {
                //setup the lambda client with the credential and endpoint information
                Amazon.Lambda.AmazonLambdaClient client = new Amazon.Lambda.AmazonLambdaClient(awsCredentials, region);

                JObject myUser = new JObject();
                myUser["id"]       = id;
                myUser["email"]    = email;
                myUser["name"]     = fname;
                myUser["nickname"] = nick;
                myUser["age"]      = age;
                myUser["gender"]   = Gender;

                //payload has to be encapsulated in double quotes, thus the strange escape sequences here
                var invokeRequest = new Amazon.Lambda.Model.InvokeRequest {
                    FunctionName = "WriteUserProfile", InvocationType = "RequestResponse", PayloadStream = AWSSDKUtils.GenerateMemoryStreamFromString(myUser.ToString()),
                };

                //going to put this task on another thread so the UI doesn't lock up
                System.Threading.Tasks.Task <Amazon.Lambda.Model.InvokeResponse> responseTask = client.InvokeAsync(invokeRequest);

                await responseTask.ContinueWith((response) =>
                {
                    string statusText        = "";
                    string informationalText = "Internal error: Unhandled branch point"; // Should always be set in the next "if"

                    if (response.IsCanceled)
                    {
                        statusText = "Cancelled"; informationalText = "";
                    }
                    else if (response.IsFaulted)
                    {
                        statusText        = "Faulted";
                        informationalText = response.Exception.Message;
                        foreach (var exception in response.Exception.InnerExceptions)
                        {
                            informationalText += "\n" + exception.Message;
                        }
                    }
                    else if (response.IsCompleted)
                    {
                        statusText         = "Finished";
                        var responseReader = new System.IO.StreamReader(response.Result.Payload);
                        informationalText  = responseReader.ReadToEnd();

                        //take the user over to the legal disclaimer step
                        var activity = new Intent(this, typeof(LegalDisclaimerActivity));
                        StartActivity(activity);
                    }

                    // This continuation is not run on the main UI thread, so need to set up
                    // another task perform the UI changes on the correct thread.
                    RunOnUiThread(() =>
                    {
                        Console.WriteLine(statusText);
                        Console.WriteLine(informationalText);
                    });
                });
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }
        private async void GetRecords()
        {
            //get the stored email of this user
            string email = prefs.GetString("email", "");

            //point the lambda call to the right location endpoint
            Amazon.RegionEndpoint region = Amazon.RegionEndpoint.USEast1;

            //credentials
            var awsCredentials = new Amazon.Runtime.BasicAWSCredentials(WebApp.AWSKey, WebApp.AWSSecret);

            TextView textHere = FindViewById <TextView>(Resource.Id.textView1);

            textHere.Text = "";
            try
            {
                //setup the lambda client with the credential and endpoint information
                Amazon.Lambda.AmazonLambdaClient client = new Amazon.Lambda.AmazonLambdaClient(awsCredentials, region);

                //payload has to be encapsulated in double quotes, thus the strange escape sequences here
                var invokeRequest = new Amazon.Lambda.Model.InvokeRequest {
                    FunctionName = "GetScanHistory", InvocationType = "RequestResponse", Payload = "\"" + email + "\""
                };

                //going to put this task on another thread so the UI doesn't lock up
                System.Threading.Tasks.Task <Amazon.Lambda.Model.InvokeResponse> responseTask = client.InvokeAsync(invokeRequest);

                await responseTask.ContinueWith((response) =>
                {
                    string statusText        = "";
                    string informationalText = "Internal error: Unhandled branch point"; // Should always be set in the next "if"

                    if (response.IsCanceled)
                    {
                        statusText = "Cancelled"; informationalText = "";
                    }
                    else if (response.IsFaulted)
                    {
                        statusText        = "Faulted";
                        informationalText = response.Exception.Message;
                        foreach (var exception in response.Exception.InnerExceptions)
                        {
                            informationalText += "\n" + exception.Message;
                        }
                    }
                    else if (response.IsCompleted)
                    {
                        statusText         = "Finished";
                        var responseReader = new System.IO.StreamReader(response.Result.Payload);
                        informationalText  = responseReader.ReadToEnd();
                    }

                    // This continuation is not run on the main UI thread, so need to set up
                    // another task perform the UI changes on the correct thread.
                    RunOnUiThread(() =>
                    {
                        Console.WriteLine(statusText);
                        Console.WriteLine(informationalText);

                        //now that we have the response we can deserialize it from Json to our object type
                        List <QRScan> scanList = JsonConvert.DeserializeObject <List <QRScan> >(informationalText);
                        foreach (QRScan scan in scanList)
                        {
                            textHere.Text += scan;
                            textHere.Text += "\n";
                        }
                    });
                });
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }