Esempio n. 1
0
        public async Task <CloudFormationResponse> CompleteCloudFormationResponse(bool success, CloudFormationRequest request, ILambdaContext context)
        {
            Log.LogInformation("Generating cloud formation response...");
            var responseBody = new CloudFormationResponse
            {
                Status             = success ? "SUCCESS" : "FAILED",
                Reason             = "See the details in CloudWatch Log Stream: " + context.LogStreamName,
                PhysicalResourceId = request.StackId,
                RequestId          = request.RequestId,
                LogicalResourceId  = request.LogicalResourceId,
                Data = null
            };

            Log.LogInformation("Sending response...");
            try
            {
                var client = new HttpClient();
                var json   = new StringContent(JsonConvert.SerializeObject(responseBody));
                json.Headers.Remove("Content-Type");

                var postResponse = await client.PutAsync(request.ResponseURL, json);

                var content = await postResponse.Content.ReadAsStringAsync();

                Log.LogInformation("Response: " + postResponse.ToJsonString() + content);
                postResponse.EnsureSuccessStatusCode();
            }
            catch (Exception ex)
            {
                Log.LogError($"ERROR: {ex.ToJsonString()}");
                responseBody.Status = "FAILED";
                responseBody.Data   = ex;
            }
            return(responseBody);
        }
Esempio n. 2
0
        public async Task OnCFTEvent(CloudFormationRequest request, ILambdaContext context)
        {
            var response = new CloudFormationResponse();

            if (!Enum.TryParse <CFTEvent>(request.RequestType, out var eventType))
            {
                Log.LogInformation($"Skipping CFT Event {request.RequestType} - no handler found.");
                await response.CompleteCloudFormationResponse(true, request, context);
            }
            else
            {
                var success = await CFTStrategies[eventType].ProcessMessageAsync(request, context);
                await response.CompleteCloudFormationResponse(success, request, context);
            }

            await Task.Run(() =>
            {
                Log.LogInformation($"CFT Event: {request}");
            });
        }