Skip to content

Commit

Permalink
fix(logging): add logs to terminate CloudFormation request (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
portellaa authored Jun 24, 2022
1 parent cc0963a commit 48b9b5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/App/HTTP/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public enum HTTP {
}

public func terminateCloudFormationInvocation<E: Encodable>(_ 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: "")
Expand All @@ -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)")
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Sources/CloudFormation/run.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 48b9b5f

Please sign in to comment.