This PR has been reworked. Instead of silently switching the default base image based on Swift version, we now: 1. **Keep Amazon Linux 2 as the default** base Docker image for the packager plugin 2. **Add a prominent deprecation warning** when AL2 is used (either via Docker or natively), informing developers that AL2 reaches End of Life on June 30, 2026 3. **Migrate all examples** (READMEs, SAM templates, scripts) to build and deploy on Amazon Linux 2023 (`provided.al2023` runtime + `--base-docker-image swift:amazonlinux2023`) 4. **Update documentation** (readme, quick-setup) with migration notes The warning includes the `--base-docker-image swift:6.3-amazonlinux2023` flag and reminds developers to use the `provided.al2023` runtime when deploying. After June 30, 2026, the default will switch to AL2023. --- <details> <summary>Original PR description (superseded)</summary> ~~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 to `amazonlinux2023`~~ ~~When only a major version is provided (e.g. `--swift-version 6` without 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-image` flag still overrides everything as before.~~ </details> --------- Co-authored-by: Sébastien Stormacq <stormacq@amazon.lu>
List Amazon S3 Buckets with Soto
This is a simple example of an AWS Lambda function that uses the Soto SDK for AWS to read data from Amazon S3.
Code
The Lambda function reads all bucket names from your AWS account and returns them as a String.
The code creates a LambdaRuntime struct. In it's simplest form, the initializer takes a function as argument. The function is the handler that will be invoked when the API Gateway receives an HTTP request.
The handler is (event: APIGatewayV2Request, context: LambdaContext) -> APIGatewayV2Response. The function takes two arguments:
- the event argument is a
APIGatewayV2Request. It is the parameter passed by the API Gateway. It contains all data passed in the HTTP request and some meta data. - the context argument is a
Lambda Context. It is a description of the runtime context.
The function must return a APIGatewayV2Response.
APIGatewayV2Request and APIGatewayV2Response are defined in the Swift AWS Lambda Events library.
The handler creates two clients : an AWS client that manages the communication with AWS API and and the S3 client that expose the S3 API. Then, the handler calls listBuckets() on the S3 client and receives an output response.
Finally, the handler extracts the list of bucket names from the output to create a \n-separated list of names, as a String.
Build & Package
To build the package, type the following command.
swift build
swift package archive --allow-network-connections docker --base-docker-image swift:amazonlinux2023
If there is no error, there is a ZIP file ready to deploy.
The ZIP file is located at .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/SotoExample/SotoExample.zip
Deploy
The deployment must include the Lambda function and an API Gateway. We use the Serverless Application Model (SAM) to deploy the infrastructure.
Prerequisites : Install the SAM CLI
The example directory contains a file named template.yaml that describes the deployment.
To actually deploy your Lambda function and create the infrastructure, type the following sam command.
sam deploy \
--resolve-s3 \
--template-file template.yaml \
--stack-name SotoExample \
--capabilities CAPABILITY_IAM
At the end of the deployment, the script lists the API Gateway endpoint. The output is similar to this one.
-----------------------------------------------------------------------------------------------------------------------------
Outputs
-----------------------------------------------------------------------------------------------------------------------------
Key APIGatewayEndpoint
Description API Gateway endpoint URL"
Value https://a5q74es3k2.execute-api.us-east-1.amazonaws.com
-----------------------------------------------------------------------------------------------------------------------------
Invoke your Lambda function
To invoke the Lambda function, use this curl command line.
curl https://a5q74es3k2.execute-api.us-east-1.amazonaws.com
Be sure to replace the URL with the API Gateway endpoint returned in the previous step.
This should print text similar to
my_bucket_1
my_bucket_2
...
Delete the infrastructure
When done testing, you can delete the infrastructure with this command.
sam delete
⚠️ Security and Reliability Notice
These are example applications for demonstration purposes. When deploying such infrastructure in production environments, we strongly encourage you to follow these best practices for improved security and resiliency:
- Enable access logging on API Gateway (documentation)
- Ensure that AWS Lambda function is configured for function-level concurrent execution limit (concurrency documentation, configuration guide)
- Check encryption settings for Lambda environment variables (documentation)
- Ensure that AWS Lambda function is configured for a Dead Letter Queue (DLQ) (documentation)
- Ensure that AWS Lambda function is configured inside a VPC when it needs to access private resources (documentation, code example)