-
Notifications
You must be signed in to change notification settings - Fork 118
improve debugging example #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...mple.xcworkspace/contents.xcworkspacedata → ...mple.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Local Debugging Example | ||
|
|
||
| This sample project demonstrates how to write a simple Lambda function in Swift, | ||
| and how to use local debugging techniques that emulate how the Lambda function | ||
| would be invoked by the AWS Lambda Runtime engine. | ||
|
|
||
| The example includes three modules: | ||
|
|
||
| 1. [MyApp](MyApp) is a SwiftUI iOS application that calls the Lambda function. | ||
| 2. [MyLambda](MyLambda) is a SwiftPM executable package for the Lambda function. | ||
| 3. [Shared](Shared) is a SwiftPM library package used for shared code between the iOS application and the Lambda function, | ||
| such as the Request and Response model objects. | ||
|
|
||
| The local debugging experience is achieved by running the Lambda function in the context of the debug only `Lambda.withLocalServer` | ||
| function which starts a local emulator enabling the communication | ||
| between the iOS application and the Lambda function over HTTP. | ||
|
|
||
| To try out this example, open the workspace in Xcode and "run" the two targets, | ||
| using the relevant `MyLambda` and `MyApp` Xcode schemas. | ||
|
|
||
| Start with running the `MyLambda` target on the "My Mac" destination, once it is up you should see a log message in the Xcode console saying | ||
| `LocalLambdaServer started and listening on 127.0.0.1:7000, receiving payloads on /invoke` | ||
| which means the local emulator is up and receiving traffic on port `7000` and expecting payloads on the `/invoke` endpoint. | ||
|
|
||
| Continue to run the `MyApp` target in a simulator destination. Once up, the application's UI should appear in the simulator allowing you | ||
| to interact with it. | ||
|
|
||
| Once both targets are running, set up breakpoints in the iOS application or Lambda function to observe the system behavior. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // swift-tools-version:5.2 | ||
| // The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
|
||
| import PackageDescription | ||
|
|
||
| let package = Package( | ||
| name: "Shared", | ||
| products: [ | ||
| .library(name: "Shared", targets: ["Shared"]), | ||
| ], | ||
| dependencies: [ | ||
| ], | ||
| targets: [ | ||
| .target(name: "Shared", dependencies: []), | ||
| ] | ||
| ) |
35 changes: 35 additions & 0 deletions
35
Examples/LocalDebugging/Shared/Sources/Shared/Shared.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the SwiftAWSLambdaRuntime open source project | ||
| // | ||
| // Copyright (c) 2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| public struct Request: Codable, CustomStringConvertible { | ||
| public let name: String | ||
| public let password: String | ||
|
|
||
| public init(name: String, password: String) { | ||
| self.name = name | ||
| self.password = password | ||
| } | ||
|
|
||
| public var description: String { | ||
| "name: \(self.name), password: ***" | ||
| } | ||
| } | ||
|
|
||
| public struct Response: Codable { | ||
| public let message: String | ||
|
|
||
| public init(message: String) { | ||
| self.message = message | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the SwiftAWSLambdaRuntime open source project | ||
| // | ||
| // Copyright (c) 2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| preconditionFailure("use `swift test --enable-test-discovery`") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps make this into a code block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will address when we merge #83 since it changes things