Ejemplo n.º 1
0
        public async Task PreTrafficHook(CodeDeployEvent deployment)
        {
            var status = LifecycleEventStatus.Succeeded;

            InitHooks();
            try
            {
                Console.WriteLine("PreHook. Version " + Env.Get("AWS_LAMBDA_FUNCTION_VERSION"));
                var tests = File.ReadAllText("smoketests.json").To <List <SmokeTest> >();
                foreach (var test in tests)
                {
                    if (!test.NoProxy)
                    {
                        var splitPath = test.Path.Trim('/').Split('/');
                        test.Path = string.Join("/", splitPath.Skip(1));
                        Console.WriteLine("Path " + test.Path);
                    }
                    var apiRequest = new APIGatewayProxyRequest
                    {
                        Path       = test.Path,
                        HttpMethod = test.Method,
                        Headers    = new Dictionary <string, string> {
                            { "Host", "localhost" }, { "__PRE_TRAFFIC_HOOK__", "true" }
                        }
                    };
                    var lambdaRequest = new InvokeRequest
                    {
                        FunctionName = Env.Get("VersionToTest"),
                        Payload      = apiRequest.ToJson()
                    };
                    var response = await _lambda.InvokeAsync(lambdaRequest);

                    using (var reader = new StreamReader(response.Payload))
                    {
                        var responseStr = reader.ReadToEnd();
                        Console.WriteLine("Response: " + responseStr);
                        var regex = new Regex(test.ResponsePattern);
                        if (!regex.IsMatch(responseStr))
                        {
                            status = LifecycleEventStatus.Failed;;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                status = LifecycleEventStatus.Failed;
                Console.WriteLine(ex.Message + " " + ex.StackTrace);
            }

            var request = new PutLifecycleEventHookExecutionStatusRequest
            {
                DeploymentId = deployment.DeploymentId,
                LifecycleEventHookExecutionId = deployment.LifecycleEventHookExecutionId,
                Status = status
            };

            await _codeDeploy.PutLifecycleEventHookExecutionStatusAsync(request);
        }
Ejemplo n.º 2
0
        // TODO: Get all docs from Mongo
        public async Task <object> getAll(APIGatewayProxyRequest request, ILambdaContext context = null)
        {
            // I expect nothing in here
            LambdaLogger.Log(request.ToJson().ToString());

            NeARandFARBackEnd.RequestUtil requestUtil = new NeARandFARBackEnd.RequestUtil();
            MongoRequest mongoRequest = new MongoRequest(requestUtil.checkRequest(request, new string[1] {
                "collection"
            }));


            JsonDocument docs = await client.getDocuments(mongoRequest);

            // return new {context = context};

            return(new MongoResponse(new BsonDocument {
                { mongoRequest.collection, docs.ToString() }
            }));
        }