Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2b5405a
WIP : init plugin
sebsto Nov 7, 2024
cc08a9a
WIP deploy plugin
sebsto Nov 7, 2024
405906f
Merge branch 'main' into sebsto/plugin-scaffold
sebsto Nov 13, 2024
9f7b043
change plugin invocation name for consistency
sebsto Nov 13, 2024
9361bed
Merge branch 'main' into sebsto/plugin-scaffold
sebsto Nov 16, 2024
bd46345
add implementation of AWS v4 Signer from aws-signer-v4 and HMAC+SHA25…
sebsto Nov 16, 2024
90517ad
swift format
sebsto Nov 16, 2024
2bdd645
WIP : migrate archive plugin to new lambda-build
sebsto Nov 17, 2024
47dd245
use Foundation to access Process on Linux
sebsto Nov 17, 2024
0665430
add --with-url option
sebsto Nov 24, 2024
0bdc813
swift format
sebsto Nov 25, 2024
0518a48
Merge branch 'main' into sebsto/new-plugins
sebsto Jan 8, 2025
3a5ef4e
Merge branch 'main' into sebsto/new-plugins
sebsto Mar 13, 2025
062c496
Merge branch 'main' into sebsto/new-plugins
sebsto Mar 13, 2025
32a0062
Merge branch 'main' into sebsto/new-plugins
sebsto Jul 30, 2025
e3a579c
minor wording changes
sebsto Jul 30, 2025
63702a5
Merge branch 'main' into sebsto/new-plugins
sebsto Sep 23, 2025
bf83300
Merge branch 'main' into sebsto/new-plugins
Oct 22, 2025
781bf3b
Merge branch 'main' into sebsto/new-plugins
sebsto Nov 2, 2025
088ac9b
Merge branch 'main' into sebsto/new-plugins
sebsto Nov 2, 2025
174c967
fix license headers
sebsto Nov 2, 2025
90ff596
fix shell check
sebsto Nov 2, 2025
6502638
more license header fixes
sebsto Nov 2, 2025
77d29af
more fixes fro shell checks
sebsto Nov 2, 2025
da47411
mor elicense fixes
sebsto Nov 2, 2025
bf73943
more license header fix
sebsto Nov 2, 2025
71c6a89
fix unit test errors on nightly-main
sebsto Nov 2, 2025
030a6c0
fix plugin package
sebsto Nov 2, 2025
728150c
fix 6.0 language mode
sebsto Nov 2, 2025
19b8ff1
Merge branch 'main' into sebsto/new-plugins
Nov 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .swiftformatignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Plugins/AWSLambdaInitializer/Template.swift
11 changes: 6 additions & 5 deletions Examples/_MyFirstFunction/create_and_deploy_function.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ check_prerequisites() {
These values are read from '~/.aws/credentials'.
"

read -r -p "Are you ready to create your first Lambda function in Swift? [y/n] " continue
if [[ ! $continue =~ ^[Yy]$ ]]; then
echo "OK, try again later when you feel ready"
exit 1
fi
printf "Are you ready to create your first Lambda function in Swift? [y/n] "
read -r continue
case $continue in
[Yy]*) ;;
*) echo "OK, try again later when you feel ready"; exit 1 ;;
esac
}

create_lambda_execution_role() {
Expand Down
53 changes: 53 additions & 0 deletions Examples/_MyFirstFunction/create_function.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
##===----------------------------------------------------------------------===##
##
## This source file is part of the SwiftAWSLambdaRuntime open source project
##
## Copyright SwiftAWSLambdaRuntime project authors
## Copyright (c) Amazon.com, Inc. or its affiliates.
## 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
##
##===----------------------------------------------------------------------===##

# check if docker is installed
if ! which docker > /dev/null; then
echo "Docker is not installed. Please install Docker and try again."
exit 1
fi

# check if user has an access key and secret access key
echo "This script creates and deploys a Lambda function on your AWS Account.

You must have an AWS account and know an AWS access key, secret access key, and an optional session token. These values are read from '~/.aws/credentials' or asked interactively.
"

printf "Are you ready to create your first Lambda function in Swift? [y/n] "
read -r continue
case $continue in
[Yy]*) ;;
*) echo "OK, try again later when you feel ready"; exit 1 ;;
esac

echo "⚡️ Create your Swift command line project"
swift package init --type executable --name MyLambda

echo "📦 Add the AWS Lambda Swift runtime to your project"
swift package add-dependency https://github.com/swift-server/swift-aws-lambda-runtime.git --branch main
swift package add-dependency https://github.com/swift-server/swift-aws-lambda-events.git --branch main
swift package add-target-dependency AWSLambdaRuntime MyLambda --package swift-aws-lambda-runtime
swift package add-target-dependency AWSLambdaEvents MyLambda --package swift-aws-lambda-events

echo "📝 Write the Swift code"
swift package lambda-init --allow-writing-to-package-directory

echo "📦 Compile and package the function for deployment"
swift package archive --allow-network-connections docker

echo "🚀 Deploy to AWS Lambda"


103 changes: 96 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,24 @@ let package = Package(
name: "swift-aws-lambda-runtime",
products: [
.library(name: "AWSLambdaRuntime", targets: ["AWSLambdaRuntime"]),

//
// The plugins
// 'lambda-init' creates a new Lambda function
// 'lambda-build' packages the Lambda function
// 'lambda-deploy' deploys the Lambda function
//
// Plugins requires Linux or at least macOS v15
//

// plugin to create a new Lambda function, based on a template
.plugin(name: "AWSLambdaInitializer", targets: ["AWSLambdaInitializer"]),

// plugin to package the lambda, creating an archive that can be uploaded to AWS
// requires Linux or at least macOS v15
.plugin(name: "AWSLambdaPackager", targets: ["AWSLambdaPackager"]),
.plugin(name: "AWSLambdaBuilder", targets: ["AWSLambdaBuilder"]),

// plugin to deploy a Lambda function
.plugin(name: "AWSLambdaDeployer", targets: ["AWSLambdaDeployer"]),
],
traits: [
"FoundationJSONSupport",
Expand Down Expand Up @@ -53,20 +68,85 @@ let package = Package(
swiftSettings: defaultSwiftSettings
),
.plugin(
name: "AWSLambdaPackager",
name: "AWSLambdaInitializer",
capability: .command(
intent: .custom(
verb: "archive",
verb: "lambda-init",
description:
"Archive the Lambda binary and prepare it for uploading to AWS. Requires docker on macOS or non Amazonlinux 2 distributions."
"Create a new Lambda function in the current project directory."
),
permissions: [
.writeToPackageDirectory(reason: "Create a file with an HelloWorld Lambda function.")
]
),
dependencies: [
.target(name: "AWSLambdaPluginHelper")
]
),
// keep this one (with "archive") to not break workflows
// This will be deprecated at some point in the future
// .plugin(
// name: "AWSLambdaPackager",
// capability: .command(
// intent: .custom(
// verb: "archive",
// description:
// "Archive the Lambda binary and prepare it for uploading to AWS. Requires docker on macOS or non Amazonlinux 2 distributions."
// ),
// permissions: [
// .allowNetworkConnections(
// scope: .docker,
// reason: "This plugin uses Docker to create the AWS Lambda ZIP package."
// )
// ]
// ),
// path: "Plugins/AWSLambdaBuilder" // same sources as the new "lambda-build" plugin
// ),
.plugin(
name: "AWSLambdaBuilder",
capability: .command(
intent: .custom(
verb: "lambda-build",
description:
"Compile and archive (zip) the Lambda binary and prepare it for uploading to AWS. Requires docker on macOS or non Amazonlinux 2 distributions."
),
permissions: [
.allowNetworkConnections(
scope: .docker,
reason: "This plugin uses Docker to create the AWS Lambda ZIP package."
reason: "This plugin uses Docker to compile code for Amazon Linux."
)
]
),
dependencies: [
.target(name: "AWSLambdaPluginHelper")
]
),
.plugin(
name: "AWSLambdaDeployer",
capability: .command(
intent: .custom(
verb: "lambda-deploy",
description:
"Deploy the Lambda function. You must have an AWS account and an access key and secret access key."
),
permissions: [
.allowNetworkConnections(
scope: .all(ports: [443]),
reason: "This plugin uses the AWS Lambda API to deploy the function."
)
]
)
),
dependencies: [
.target(name: "AWSLambdaPluginHelper")
]
),
.executableTarget(
name: "AWSLambdaPluginHelper",
dependencies: [
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
],
swiftSettings: defaultSwiftSettings
),
.testTarget(
name: "AWSLambdaRuntimeTests",
Expand All @@ -89,5 +169,14 @@ let package = Package(
],
swiftSettings: defaultSwiftSettings
),
.testTarget(
name: "AWSLambdaPluginHelperTests",
dependencies: [
.byName(name: "AWSLambdaPluginHelper"),
.product(name: "Logging", package: "swift-log"),
],
swiftSettings: defaultSwiftSettings
),

]
)
94 changes: 87 additions & 7 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,24 @@ let package = Package(
name: "swift-aws-lambda-runtime",
products: [
.library(name: "AWSLambdaRuntime", targets: ["AWSLambdaRuntime"]),

//
// The plugins
// 'lambda-init' creates a new Lambda function
// 'lambda-build' packages the Lambda function
// 'lambda-deploy' deploys the Lambda function
//
// Plugins requires Linux or at least macOS v15
//

// plugin to create a new Lambda function, based on a template
.plugin(name: "AWSLambdaInitializer", targets: ["AWSLambdaInitializer"]),

// plugin to package the lambda, creating an archive that can be uploaded to AWS
// requires Linux or at least macOS v15
.plugin(name: "AWSLambdaPackager", targets: ["AWSLambdaPackager"]),
.plugin(name: "AWSLambdaBuilder", targets: ["AWSLambdaBuilder"]),

// plugin to deploy a Lambda function
.plugin(name: "AWSLambdaDeployer", targets: ["AWSLambdaDeployer"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.81.0"),
Expand All @@ -39,20 +54,85 @@ let package = Package(
swiftSettings: defaultSwiftSettings
),
.plugin(
name: "AWSLambdaPackager",
name: "AWSLambdaInitializer",
capability: .command(
intent: .custom(
verb: "lambda-init",
description:
"Create a new Lambda function in the current project directory."
),
permissions: [
.writeToPackageDirectory(reason: "Create a file with an HelloWorld Lambda function.")
]
),
dependencies: [
.target(name: "AWSLambdaPluginHelper")
]
),
// keep this one (with "archive") to not break workflows
// This will be deprecated at some point in the future
// .plugin(
// name: "AWSLambdaPackager",
// capability: .command(
// intent: .custom(
// verb: "archive",
// description:
// "Archive the Lambda binary and prepare it for uploading to AWS. Requires docker on macOS or non Amazonlinux 2 distributions."
// ),
// permissions: [
// .allowNetworkConnections(
// scope: .docker,
// reason: "This plugin uses Docker to create the AWS Lambda ZIP package."
// )
// ]
// ),
// path: "Plugins/AWSLambdaBuilder" // same sources as the new "lambda-build" plugin
// ),
.plugin(
name: "AWSLambdaBuilder",
capability: .command(
intent: .custom(
verb: "archive",
verb: "lambda-build",
description:
"Archive the Lambda binary and prepare it for uploading to AWS. Requires docker on macOS or non Amazonlinux 2 distributions."
"Compile and archive (zip) the Lambda binary and prepare it for uploading to AWS. Requires docker on macOS or non Amazonlinux 2 distributions."
),
permissions: [
.allowNetworkConnections(
scope: .docker,
reason: "This plugin uses Docker to create the AWS Lambda ZIP package."
reason: "This plugin uses Docker to compile code for Amazon Linux."
)
]
),
dependencies: [
.target(name: "AWSLambdaPluginHelper")
]
),
.plugin(
name: "AWSLambdaDeployer",
capability: .command(
intent: .custom(
verb: "lambda-deploy",
description:
"Deploy the Lambda function. You must have an AWS account and an access key and secret access key."
),
permissions: [
.allowNetworkConnections(
scope: .all(ports: [443]),
reason: "This plugin uses the AWS Lambda API to deploy the function."
)
]
)
),
dependencies: [
.target(name: "AWSLambdaPluginHelper")
]
),
.executableTarget(
name: "AWSLambdaPluginHelper",
dependencies: [
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
],
swiftSettings: defaultSwiftSettings
),
.testTarget(
name: "AWSLambdaRuntimeTests",
Expand Down
Loading
Loading