You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Plugins/Documentation.docc/Proposals/0001-v2-plugins.md
+37-31Lines changed: 37 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ As a source of inspiration, we looked to the Rust community, which created Cargo
22
22
23
23
### Current Limitations
24
24
25
-
The current version of `swift-aws-lambda-runtime` does not provide any support for project scaffolding or deployment of Lambda functions. This makes it difficult for Swift developers new to AWS and Lambda, or AWS Professionals new to Swift, to get started.
25
+
The current version of `swift-aws-lambda-runtime` does not provide any support for project **scaffolding** or **deployment** of Lambda functions. This makes it difficult for Swift developers new to AWS and Lambda, or AWS Professionals new to Swift, to get started.
26
26
27
27
The main limitations of the current version of the `archive` plugin are as follows:
28
28
@@ -43,15 +43,13 @@ We may consider additional plugins in a future release. For example, we could co
43
43
44
44
## Detailed Solution
45
45
46
-
### Dependencies
47
-
48
-
One of the design objective of the Swift AWS Lambda Runtime is to minimize its dependencies on other libraries. We will strive to keep the dependencies of the plugins to a minimum.
46
+
The proposed solution consists of three new plugins: `lambda-init`, `lambda-build`, and `lambda-deploy`. These plugins will assist developers in creating, building, packaging, and deploying Lambda functions.
49
47
50
48
### Create a New Project (lambda-init)
51
49
52
-
The `lambda-init` plugin will assist developers in creating a new Lambda project from scratch. The plugin will scaffold the project code. It will create a ready-to-deploy`main.swift` file containing a simple Lambda function. The plugin will allow users to choose from a selection of basic templates, such as a simple "Hello World" Lambda function or a function invoked by a URL.
50
+
The `lambda-init` plugin will assist developers in creating a new Lambda project from scratch. The plugin will scaffold the project code. It will create a ready-to-build`main.swift` file containing a simple Lambda function. The plugin will allow users to choose from a selection of basic templates, such as a simple "Hello World" Lambda function or a function invoked by a URL.
53
51
54
-
The plugin cannot be invoked without the required dependencies installed in `Package.swift`. The process of creating a new project will consist of three steps and four commands, all executable from the command line:
52
+
The plugin cannot be invoked without the required dependency on `swift-aws-lambda-runtime` project being configured in `Package.swift`. The process of creating a new project will consist of three steps and four commands, all executable from the command line:
55
53
56
54
```bash
57
55
# Step 1: Create a new Swift executable package
@@ -92,7 +90,7 @@ The `lambda-build` plugin will assist developers in building and packaging their
92
90
93
91
We also propose to automatically strip the binary of debug symbols to reduce the size of the ZIP file. Our tests showed that this can reduce the size by up to 50%. An option to disable stripping will be provided.
94
92
95
-
The `lambda-build` plugin is similar to the existing `archive` plugin. We propose to keep the same interface to facilitate migration of existing projects. If technically feasible, we will also consider keeping the `archive` plugin as an alias to the `lambda-build` plugin.
93
+
The `lambda-build` plugin is similar to the existing `archive` plugin. We propose to keep the same interface to facilitate migration of existing projects and CI chains. If technically feasible, we will also consider keeping the `archive` plugin as an alias to the `lambda-build` plugin.
96
94
97
95
The plugin interface is based on the existing `archive` plugin, with the addition of the `--no-strip` and `--cross-compile` options:
98
96
@@ -101,15 +99,17 @@ OVERVIEW: A SwiftPM plugin to build and package your Lambda function.
101
99
102
100
REQUIREMENTS: To use this plugin, Docker must be installed and running.
103
101
104
-
USAGE: swift package --allow-network-connections docker archive
105
-
[--help] [--verbose]
106
-
[--output-directory <path>]
107
-
[--products <list of products>]
108
-
[--configuration debug | release]
109
-
[--swift-version <version>]
110
-
[--base-docker-image <docker_image_name>]
111
-
[--disable-docker-image-update]
112
-
102
+
USAGE: swift package archive
103
+
[--help] [--verbose]
104
+
[--output-directory <path>]
105
+
[--products <list of products>]
106
+
[--configuration debug | release]
107
+
[--swift-version <version>]
108
+
[--base-docker-image <docker_image_name>]
109
+
[--disable-docker-image-update]
110
+
[--no-strip]
111
+
[--cross-compile <value>]
112
+
[--allow-network-connections docker]
113
113
114
114
OPTIONS:
115
115
--output-directory <path> The path of the binary package.
@@ -125,14 +125,19 @@ OPTIONS:
125
125
(default: swift-<version>:amazonlinux2)
126
126
This parameter cannot be used with --swift-version.
127
127
This parameter cannot be used with a value other than Docker provided to --cross-compile.
128
-
--disable-docker-image
128
+
--disable-docker-image-update Do not update the Docker image before building.
129
+
--no-strip Do not strip the binary of debug symbols.
130
+
--cross-compile <value> Cross-compile the binary using the specified method.
The `lambda-deploy` plugin will assist developers in deploying their Lambda function to AWS. It will handle the deployment process, including creating the IAM role, the Lambda function itself, and optionally configuring a Lambda function URL.
134
137
135
-
The plugin will not require any additional dependencies. It will interact with the AWS REST API directly, without using the AWS SDK fro Swift or Soto. Users will need to provide AWS access key and secret access key credentials. The plugin will attempt to locate these credentials in standard locations, such as environment variables or the `~/.aws/credentials` file.
138
+
The plugin will not depends on nay third-party library. It will interact directly with the AWS REST API, without using the AWS SDK fro Swift or Soto.
139
+
140
+
Users will need to provide AWS access key and secret access key credentials. The plugin will attempt to locate these credentials in standard locations, such as environment variables or the `~/.aws/credentials` file.
136
141
137
142
The plugin supports deployment through either the REST and Base64 payload or by uploading the code to a temporary S3 bucket. Refer to [the `Function Code` section](https://docs.aws.amazon.com/lambda/latest/api/API_FunctionCode.html) of the [CreateFunction](https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html) API for more details.
138
143
@@ -152,6 +157,9 @@ OVERVIEW: A SwiftPM plugin to deploy a Lambda function.
152
157
153
158
USAGE: swift package lambda-deploy
154
159
[--with-url]
160
+
[--region <value>]
161
+
[--iam-role <value>]
162
+
[--delete]
155
163
[--help] [--verbose]
156
164
157
165
OPTIONS:
@@ -168,11 +176,13 @@ OPTIONS:
168
176
169
177
### Dependencies
170
178
171
-
Minimizing dependencies is a key priority for the plugins. We aim to avoid including unnecessary dependencies, such as the AWS SDK for Swift or Soto, for the `lambda-deploy` plugin.
179
+
One of the design objective of the Swift AWS Lambda Runtime is to minimize its dependencies on other libraries.
172
180
173
-
Four essential dependencies have been identified for the plugins:
181
+
Therefore, minimizing dependencies is a key priority for the new plugins. We aim to avoid including unnecessary dependencies, such as the AWS SDK for Swift or Soto, for the `lambda-deploy` plugin.
174
182
175
-
* an argument parser
183
+
Four essential dependencies have been identified to implement the plugins:
184
+
185
+
* an command line argument parser
176
186
* an HTTP client
177
187
* a library to sign AWS requests
178
188
* a library to calculate HMAC-SHA256 (used in the AWS signing process)
@@ -181,7 +191,7 @@ These functionalities can be incorporated by vending source code from other proj
181
191
182
192
**Argument Parser:**
183
193
184
-
* We will leverage the `ArgumentExtractor` from the `swift-package-manager` project ([https://github.com/swiftlang/swift-package-manager/blob/main/Sources/PackagePlugin/ArgumentExtractor.swift](https://github.com/swiftlang/swift-package-manager/blob/main/Sources/PackagePlugin/ArgumentExtractor.swift)). This is a simple argument parser used by the Swift Package Manager. The relevant files will be copied into the plugin.
194
+
* We propose to leverage the `ArgumentExtractor` from the `swift-package-manager` project ([https://github.com/swiftlang/swift-package-manager/blob/main/Sources/PackagePlugin/ArgumentExtractor.swift](https://github.com/swiftlang/swift-package-manager/blob/main/Sources/PackagePlugin/ArgumentExtractor.swift)). This is a simple argument parser used by the Swift Package Manager. The relevant files will be copied into the plugin.
185
195
186
196
**HTTP Client:**
187
197
@@ -199,7 +209,7 @@ These functionalities can be incorporated by vending source code from other proj
199
209
200
210
The dependencies will be vendored within the plugin and will not be listed as dependencies in the `Package.swift` file.
201
211
202
-
The following files will be copied into the plugin, without modifications from their original projects:
212
+
If we follow that plan, the following files will be copied into the plugin, without modifications from their original projects:
SwiftPM plugin can not share code within sources files or using a shared Library target. The recommended way to share code between plugins is to create an executable target to implement the plugin functionalities and to implement the plugin as a thin wrapper that invokes the executable target.
248
+
SwiftPM plugins from a same project can not share code in between sources files or using a shared Library target. The recommended way to share code between plugins is to create an executable target to implement the plugin functionalities and to implement the plugin as a thin wrapper that invokes the executable target.
239
249
240
250
We propose to add an executable target and three plugins to the `Package.swift` file of the `swift-aws-lambda-runtime` package.
241
251
@@ -249,11 +259,7 @@ let package = Package(
249
259
// The runtime library targets
250
260
//
251
261
252
-
// this library exports `AWSLambdaRuntimeCore` and adds Foundation convenience methods
@@ -430,9 +436,9 @@ In addition to the proposed solution, we evaluated the following alternatives:
430
436
431
437
We considered using a VSCode extension, such as the `vscode-aws-lambda-swift-sam` extension ([https://github.com/swift-server-community/vscode-aws-lambda-swift-sam](https://github.com/swift-server-community/vscode-aws-lambda-swift-sam)), to scaffold new Lambda projects.
432
438
433
-
This extension creates a new Lambda project from scratch, including the project structure and dependencies. It provides a ready-to-deploy`main.swift` file with a simple Lambda function and allows users to choose from basic templates, such as "Hello World" or an OpenAPI-based function. However, the extension relies on the AWS CLI and SAM CLI for deployment. It is only available in the Visual Studio Code Marketplace.
439
+
This extension creates a new Lambda project from scratch, including the project structure and dependencies. It provides a ready-to-build`main.swift` file with a simple Lambda function and allows users to choose from basic templates, such as "Hello World" or an OpenAPI-based Lambda function. However, the extension relies on the AWS CLI and SAM CLI for deployment. It is only available in the Visual Studio Code Marketplace.
434
440
435
-
While the extension offers a user-friendly graphical interface, it does not align well with our goals of simplicity for first-time users and minimal dependencies. Users would need to install VSCode, the extension itself, the AWS CLI, and the SAM CLI before getting started.
441
+
While the extension offers a user-friendly graphical interface, it does not align well with our goals of simplicity for first-time users and minimal dependencies. Users would need to install and configure VSCode, the extension itself, the AWS CLI, and the SAM CLI before getting started.
0 commit comments