[plugin] Display a warning when compiling on Amazon Linux 2 and optin documentation and examples for Amazon Linux 2023#668
Conversation
|
The swift-nightly-main failure is unrelated to this PR. It is caused by stricter region-isolation diagnostics in the nightly compiler hitting the current pinned version of swift-async-algorithms (MultiProducerSingleConsumerAsyncChannel+Internal.swift). See apple/swift-async-algorithms#418. |
|
Hey @MahdiBM Can you have a look and comment on this change ? |
25bfae1 to
6bbb23b
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the Lambda packager to select Amazon Linux 2023 Swift Docker images by default for Swift 6.3+ while preserving Amazon Linux 2 for older Swift versions.
Changes:
- Adds Swift-version-based Amazon Linux image selection and verbose logging in the packager plugin.
- Bumps several package dependency minimum versions.
- Adds documentation for the ResourcesPackaging example and links it from the examples index.
Reviewed changes
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
Plugins/AWSLambdaPackager/Plugin.swift |
Updates default Docker image selection and help text for Amazon Linux 2023/2. |
Package.swift |
Raises minimum versions for NIO, swift-log, swift-collections, and service-lifecycle. |
Examples/ResourcesPackaging/README.md |
Adds usage, deployment, invocation, and cleanup instructions for the resources packaging example. |
Examples/README.md |
Adds the ResourcesPackaging example to the examples list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Technically speaking, any app that runs on Swift 6.2 and below should also be able to run on Swift 6.3. So checking the Swift version is probably not very helpful. A swift version upgrade is supposed to always work out, although sometimes it can go wrong when the newer compiler comes with some issues or bugs. I'm only worried maybe some people are relying on the plugin using amazonlinux2 images. If that is a concern (e.g. if something breaks when you upload a amazonlinux2023 executable to a amazonlinux2 aws lambda) then the safest option would be to print a big scary warning by default and mention that they should pass some kind of flag to ensure they'll use amazon linux 2023 since amazon linux 2 is very outdated 🤔. So yeah. I'm not sure how gracefully AWS handles that. If things will be just fine, then we can take a bit of a risk and just get rid of amazon Linux 2. Otherwise the safer option is a big warning to ask users to manually choose amazonlinux2023 (--base-docker-image swift:amazonlinux2023 ?), IMO. |
|
Good points. Let me address them: On the Swift version check: You're right that a package targeting swift-tools-version 6.1 will compile fine with the Swift 6.3 compiler (source compatibility is forward). The On the real risk (build/deploy mismatch): The actual concern is not Swift version compatibility but OS-level library compatibility. So the build environment and the Lambda runtime must match. This was already the case before this PR (build on AL2 → deploy to On the approach: I think we can simplify: always default to This makes the migration explicit without being scary. Users who still need AL2 have a clear escape hatch. What do you think? |
|
So ... I think we should take the safer approach unless we can confirm just updating to al2023 will not cause issues for like more than ~1% of the users. The actual issue is that users will need to manually update to provided.al2023. So unless someone with deep knowledge/experience can come through and say the risk is very low, we should take the safer route IMO. In the future we can still change the default to 2023 if we ever think it's a safe default. |
|
Which then means we'll also have to update the docs and mention that they default al2 is only kept for legacy reasons and users should theoretically always pass that argument to make the plugin use al2023, if the machine they're building on is not already al2023. Also ... a question. Penny CI builds stuff in an amazonlinux2023 container. Shouldn't the plugin simply just use the environment instead of using the al2 default? |
|
Hello @MahdiBM The ABI compatibility is not in the discussion because the binaries are statically linked with all Swift libraries. The risk is about system libraries, such as libgc and the crypto ones. If I summarize your message, you're suggesting to have an Amazon Linux 2023 compilation as an opt-in flag to avoid breaking builds or deployments. I kind of agree with that suggestion. Let's bring in the wider community for discussion before taking a decision. |
|
@MahdiBM I apologize for the pause working on this. I pushed a set of changes to address your feedback. Instead of silently switching the default base image, the plugin now keeps AL2 as the default and displays a prominent deprecation warning when AL2 is used. All examples have been migrated to build and deploy on AL2023. Please take a look when you get a chance. |
|
Here is the output when compiling on Amazon Linux 2 ➜ HelloJSON git:(plugin/amazonlinux2023) LAMBDA_USE_LOCAL_DEPS=../.. swift package archive --allow-network-connections docker
====================================================================
WARNING: Amazon Linux 2 reaches End of Life on June 30, 2026.
You must migrate to Amazon Linux 2023.
Amazon Linux 2023 will become the default after June 30, 2026.
To switch now, re-run with:
--base-docker-image swift:amazonlinux2023
When using Amazon Linux 2023, you must also update your Lambda
deployment to use the provided.al2023 runtime.
For more information: https://aws.amazon.com/amazon-linux-2
====================================================================
-------------------------------------------------------------------------
building "hellojson" in docker
-------------------------------------------------------------------------
updating "swift:amazonlinux2" image
amazonlinux2: Pulling from library/swift
Digest: sha256:49ad698b70e08c773f378b3616b272dc070cdd5e04935208714064ceab060dc2
Status: Image is up to date for swift:amazonlinux2
docker.io/library/swift:amazonlinux2
building "HelloJSON"
[0/1] Planning build
Building for production...
[0/3] Write sources
[1/3] Write swift-version-24593BA9C3E375BF.txt
[3/4] Compiling AWSLambdaRuntime Context+Foundation.swift
[4/6] Compiling HelloJSON main.swift
[4/6] Write Objects.LinkFileList
/usr/lib/swift_static/linux/libFoundationEssentials.a(Data+Writing.swift.o):_ThreadLocal.swift.o:function $s20FoundationEssentials19createTemporaryFile33_FC9EC52B075D2ACCFF86F1C9F84293BELL2at6inPath6prefix7options7variants5Int32V_SStSS_AA0Q5OrURLOSSAA4DataV14WritingOptionsVSSSgtKFAJ_SStSgSpys4Int8VGSgKXEfU_: warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
[5/6] Linking HelloJSON
Build of product 'HelloJSON' complete! (20.66s)
-------------------------------------------------------------------------
archiving "HelloJSON"
-------------------------------------------------------------------------
1 archive created
* HelloJSON at /Users/stormacq/Documents/code-amzn/swift/lambda/swift-aws-lambda-runtime/Examples/HelloJSON/.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/HelloJSON/HelloJSON.zip |
|
and here is the output when compiling on Amazon Linux 2023 ➜ HelloJSON git:(plugin/amazonlinux2023) ✗ LAMBDA_USE_LOCAL_DEPS=../.. swift package archive --allow-network-connections docker --base-docker-image swift:amazonlinux2023
-------------------------------------------------------------------------
building "hellojson" in docker
-------------------------------------------------------------------------
updating "swift:amazonlinux2023" image
amazonlinux2023: Pulling from library/swift
Digest: sha256:dab6dd1e149263977ca6e833a748c12d8e777c9da6772180413a6db0c694143c
Status: Image is up to date for swift:amazonlinux2023
docker.io/library/swift:amazonlinux2023
building "HelloJSON"
[0/1] Planning build
Building for production...
[0/2] Write swift-version-24593BA9C3E375BF.txt
...
[29/31] Compiling HelloJSON main.swift
[29/31] Write Objects.LinkFileList
/usr/bin/ld: /usr/lib/swift_static/linux/libFoundationEssentials.a(Data+Writing.swift.o): in function `$s20FoundationEssentials19createTemporaryFile33_FC9EC52B075D2ACCFF86F1C9F84293BELL2at6inPath6prefix7options7variants5Int32V_SStSS_AA0Q5OrURLOSSAA4DataV14WritingOptionsVSSSgtKFAJ_SStSgSpys4Int8VGSgKXEfU_':
_ThreadLocal.swift.o:(.text+0x804): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
[30/31] Linking HelloJSON
Build of product 'HelloJSON' complete! (75.38s)
-------------------------------------------------------------------------
archiving "HelloJSON"
-------------------------------------------------------------------------
1 archive created
* HelloJSON at /Users/stormacq/Documents/code-amzn/swift/lambda/swift-aws-lambda-runtime/Examples/HelloJSON/.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/HelloJSON/HelloJSON.zip |
This PR has been reworked. Instead of silently switching the default base image based on Swift version, we now:
provided.al2023runtime +--base-docker-image swift:amazonlinux2023)The warning includes the
--base-docker-image swift:6.3-amazonlinux2023flag and reminds developers to use theprovided.al2023runtime when deploying.After June 30, 2026, the default will switch to AL2023.
Original PR description (superseded)
Now that Docker Hub has official Swift images based on Amazon Linux 2023 (starting with 6.3), the packager plugin picks the right base image automatically depending on the Swift version:- Swift 6.3 and later:swift:<version>-amazonlinux2023- Earlier versions:swift:<version>-amazonlinux2(unchanged behavior)- No version specified (latest): defaults toamazonlinux2023When only a major version is provided (e.g.--swift-version 6without a minor), we conservatively treat it as 6.0 and use Amazon Linux 2, since we can't be sure it's 6.3+.Also added a verbose log line showing the resolved Swift version, Amazon Linux version, and final base image to help with debugging.The--base-docker-imageflag still overrides everything as before.