Comments (3)
One solution that worked for me is to consider both MyLambda
and Shared
as one package, i.e.
- delete
MyLambda/Package.swift
- delete
Shared/Package.swift
- create
./Package.swift
at root directory level (Examples/LocalDebugging
) with the following content
import PackageDescription
let package = Package(
name: "MyLambda",
platforms: [
.macOS(.v12),
],
products: [
.executable(name: "MyLambda", targets: ["MyLambda"]),
.library(name: "Shared", targets: ["Shared"]),
],
dependencies: [
// this is the dependency on the swift-aws-lambda-runtime library
// in real-world projects this would say
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main"),
// .package(name: "swift-aws-lambda-runtime", path: "../../.."),
],
targets: [
.executableTarget(
name: "MyLambda",
dependencies: [
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
.byName(name: "Shared"),
],
path: "./MyLambda",
exclude: ["scripts/", "Dockerfile"]
),
.target(name: "Shared",
dependencies: [],
path: "./Shared")
]
)
That allows to build and archive the Shared
library and the MyLambda
lambda function.
➜ LocalDebugging git:(master) ✗ swift build
warning: 'localdebugging': found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
/Users/stormacq/Documents/amazon/code/lambda/swift/swift-aws-lambda-runtime/Examples/LocalDebugging/Shared/Package.swift.ignore
warning: 'localdebugging': found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
/Users/stormacq/Documents/amazon/code/lambda/swift/swift-aws-lambda-runtime/Examples/LocalDebugging/MyLambda/Package.swift.ignore
[1/1] Planning buildCompiling plugin AWSLambdaPackager...
Building for debugging...
Build complete! (0.30s)
➜ LocalDebugging git:(master) ✗
➜ LocalDebugging git:(master) ✗ swift package --disable-sandbox archive --verbose 1 --output-path dist
-------------------------------------------------------------------------
configuration
-------------------------------------------------------------------------
{
outputDirectory: dist
products: ["MyLambda"]
buildConfiguration: release
baseDockerImage: swift:amazonlinux2
}
-------------------------------------------------------------------------
building "localdebugging" in docker
-------------------------------------------------------------------------
updating "swift:amazonlinux2" docker image
amazonlinux2: Pulling from library/swift
Digest: sha256:0b645a7589aa5f1759f976c42a9ffba48fd930b27b3481b0ab32e271e701d444
Status: Image is up to date for swift:amazonlinux2
docker.io/library/swift:amazonlinux2
/usr/local/bin/docker run --rm -v /Users/stormacq/Documents/amazon/code/lambda/swift/swift-aws-lambda-runtime/Examples/LocalDebugging:/workspace -w /workspace swift:amazonlinux2 bash -cl swift build -c release --show-bin-path
/workspace/.build/aarch64-unknown-linux-gnu/release
building "MyLambda"
/usr/local/bin/docker run --rm -v /Users/stormacq/Documents/amazon/code/lambda/swift/swift-aws-lambda-runtime/Examples/LocalDebugging:/workspace -w /workspace swift:amazonlinux2 bash -cl swift build -c release --product MyLambda --static-swift-stdlib
warning: 'workspace': found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
/workspace/Shared/Package.swift.ignore
warning: 'workspace': found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
/workspace/MyLambda/Package.swift.ignore
[0/1] Planning build
Building for production...
Build complete! (2.00s)
-------------------------------------------------------------------------
archiving "MyLambda"
-------------------------------------------------------------------------
/usr/bin/zip --junk-paths --symlinks dist/MyLambda/MyLambda.zip dist/MyLambda/MyLambda dist/MyLambda/bootstrap
adding: MyLambda
(deflated 66%)
adding: bootstrap
(stored 0%)
1 archive created
* MyLambda at dist/MyLambda/MyLambda.zip
from swift-aws-lambda-runtime.
interesting issue. the archive plugin assumes the lambda is self contained and no external file system dependencies outside the package directory. in concept, the command should be invoked from Examples/LocalDebugging/MyLambda
and not the root of the example Examples/LocalDebugging
, but as mentioned above the docker bind mount will not "see" the shared module. this requires more thinking. I think re-arranging the example as suggested defeats the idea of having a shared module across the lambda and iOS app?
from swift-aws-lambda-runtime.
Thank you Tom. Looks like the old debate about mono vs. multi repositories.
I re-arranged the package structure to share the same Package.swift
for the targets MyLambda
and Shared
. This allows the plugin to build and archive MyLamba
. At the same time, I also made minimum changes to the Xcode workspace to continue to be able to build and debug from Xcode.
That way, the iOS app still depends on the Swift package. However, with this approach, Xcode sees both MyLambda
and Shared
. This structure kind off transfers "ownership" of the shared library to the "MyLambda" project. It will not work in larger teams where three different teams would maintain these three artifacts.
Project now builds with swift build
It runs with export LOCAL_LAMBDA_SERVER_ENABLED=true && swift run MyLambda
.
It packages with swift package --disable-sandbox archive
It runs by selecting the MyLambda
target in Xcode
It runs by selecting the MyApp
target in Xcode
Agree with you that more thinking or feedback is required on that one.
from swift-aws-lambda-runtime.
Related Issues (20)
- Totally remove dependency on Foundation HOT 3
- Runtime not populating `APIGateway.V2.Request` properties HOT 1
- Support bootstrapping the LoggingSystem in Lambda.run's factory
- Use primary associated type to reduce boilerplate HOT 1
- Plugin does not work HOT 4
- [plugin] Provided Examples' Package.swift does not work with the archive plugin. HOT 2
- Replacement for Lambda.run? HOT 5
- How to fix newline in input causing Swift AWS lambda to fail in localhost testing HOT 2
- README.MD example about SimpleLambdaHandler HOT 3
- Archive plugin execution error with AWS SDK HOT 14
- Discussions repository Feature HOT 5
- Archive plugin to generate libraries (*.so) HOT 2
- [Request] Support Serverless Framework with a plugin? HOT 6
- [Idea] Could Lambda Layers Custom Runtime improve cold start performance? HOT 3
- [Feature Request] Somehow don't touch Package.resolved during lambda package archive to work better with VSCode. HOT 1
- [BUG] Can't compile code with NSFileCoordinator (cannot find in scope) HOT 3
- CI builds fails with Swift 5.9 and Swift nightly HOT 4
- [Question] Can DocC remove license headers from source code file HOT 4
- Add support for SPM Resources HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-aws-lambda-runtime.