diff --git a/Sources/App/HTTP/HTTPClient.swift b/Sources/App/HTTP/HTTPClient.swift index 52abeaf..ae60f3b 100644 --- a/Sources/App/HTTP/HTTPClient.swift +++ b/Sources/App/HTTP/HTTPClient.swift @@ -20,6 +20,8 @@ public enum HTTP { } public func terminateCloudFormationInvocation(_ url: String, event: E) async throws { + logger.info("CloudFormation will terminate with url \(url)") + var request = HTTPClientRequest(url: url) request.headers.add(name: "Content-Type", value: "") @@ -29,9 +31,16 @@ public enum HTTP { request.body = .bytes(byteBuffer) let response = try await provider.execute(request, timeout: .seconds(30), logger: logger) + + logger.debug("CloudFormation got response for url \(url)\n\(response)") + if response.status != .ok { + logger.error("CloudFormation terminated for url \(url) with error)") + throw Error.failedWithResponse(response) } + + logger.info("CloudFormation did terminate with url \(url)") } } } diff --git a/Sources/CloudFormation/run.swift b/Sources/CloudFormation/run.swift index 0f25c96..f3391cd 100644 --- a/Sources/CloudFormation/run.swift +++ b/Sources/CloudFormation/run.swift @@ -23,12 +23,18 @@ struct CloudFormationHandler: LambdaHandler { } func handle(_ event: Event, context: LambdaContext) async throws -> Output { + context.logger.info("running lambda with event \n\(event)") + guard let resourceProperties = event.resourceProperties else { throw Error.missingResourceProperties } + context.logger.info("extracted resource properties\n\(resourceProperties)") + let response = await app.run(with: resourceProperties, runContext: context).encode(for: event) + context.logger.info("got response\n\(response)") + try await httpClient.terminateCloudFormationInvocation(event.responseURL, event: response) } }