swift-server / swift-aws-lambda-runtime

Swift implementation of AWS Lambda Runtime
Apache License 2.0
1.12k stars 100 forks source link

Add support for SPM Resources #312

Open johnbona opened 7 months ago

johnbona commented 7 months ago

Expected behavior

Hello!

We're looking to utilize PhoneNumberKit which packages Google's libphonenumber metadata for phone number validation.

When archiving the project using the built-in AWSLambdaPackager plugin, the project successfully compiles and generates the .zip to upload to AWS. Given that PhoneNumberKit declares the Google libphonenumber metadata as a resource for the target, it's expected that AWSLambdaPackager would include the resource in the generated .zip file.

For reference, the swift-lambda project added support for SPM resources with this commit: https://github.com/SwiftXcode/swift-lambda/commit/dac42bc867319cfe7d48fd4f39f12a6468c0274c

Actual behavior

The AWSLambdaPackager plugin does not include SPM resources in the .zip and at runtime, the lambda crashes with the following error:

PhoneNumberKit/resource_bundle_accessor.swift:11: Fatal error: could not load resource bundle: from /var/task/PhoneNumberKit_PhoneNumberKit.resources or /workspace/.build/aarch64-unknown-linux-gnu/release/PhoneNumberKit_PhoneNumberKit.resources

Steps to reproduce

  1. Create a "Hello World" lambda declaring PhoneNumberKit as a dependency
  2. Add let phoneNumberKit = PhoneNumberKit()
  3. Execute the lambda and will crash when PhoneNumberKit attempts to load the libphonenumber metadata resource

If possible, minimal yet complete reproducer code (or URL to code)

No response

What version of this project (swift-aws-lambda-runtime) are you using?

main

Swift version

swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
Target: arm64-apple-macosx14.0
Darwin Computer.local 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000 arm64

Amazon Linux 2 docker image version

5.9-amazonlinux2

sebsto commented 2 weeks ago

@johnbona Can you review #333 and let us know if this implementation would match your needs. I'm curious to learn about the requirement for the directory name. Can you customize it on PhoneNumberKit side ? Or is it expected to be a specific name ?