Ejemplo n.º 1
0
        /// <summary>
        /// A Lambda function to respond to HTTP Get methods from API Gateway
        /// </summary>
        /// <param name="request"></param>
        /// <returns>The list of blogs</returns>
        public APIGatewayProxyResponse Get(APIGatewayProxyRequest request, ILambdaContext context)
        {
            context?.Logger.LogLine("Get Request\n");

            string JSONstring = "";

            //var credentials = new StoredProfileAWSCredentials("LinkLiang");
            //using (var client = new AmazonLambdaClient(credentials,RegionEndpoint.USEast1))
            using (var client = new AmazonLambdaClient())
            {
                var load = JsonConvert.SerializeObject(request.Body);
                var req  = new InvokeRequest()
                {
                    FunctionName = "PDF2Raw",
                    Payload      = "\"" + request.Body + "\""
                };

                context?.Logger.LogLine(req.ToString());
                var res = client.InvokeAsync(req).GetAwaiter().GetResult();

                using (var sr = new StreamReader(res.Payload))
                {
                    JSONstring = sr.ReadToEnd();
                }
            }

            Parser parse  = SelectCustomer(JSONstring);
            string result = parse.Parse(JSONstring);

            context?.Logger.LogLine(result);

            var response = new APIGatewayProxyResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                Body       = result,
                Headers    = new Dictionary <string, string> {
                    { "Content-Type", "application/json" }
                }
            };

            return(response);
        }