-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[doc] add a deployment guide and update the readme #432
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall it looks good. One typo and a few things to discuss
|
||
![Console - select zip file](console-40-select-zip-file) | ||
|
||
Select the zip file created with the `swift package archive --allow-network-connections docker` command. This file is located in your project folder at `.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/MyLambda.zip`. The name of the ZIP file depends on the target name you entered in the `Package.swift` file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a tutorial on this command we can link to? It came very out of the blue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doc is about the deployment, so after the package is compiled and zipped.
But you're right, I should add a paragraph on top repeating the requirement : having a Swift lambda function compiled and ZIP. This applies to all deployment techniques presented in this doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'd add that before going into all the different examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I added a section in the prerequisites
|
||
### Invoke the function | ||
|
||
Select the **Test** tab in the console and prepare a payload to send to your Lambda function. In this example, you've deployed the [HelloWorld](Exmaples.HelloWorld/README.md) example function. The function expects a `String` as input parameter and returns a `String`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This either needs rewording or we need to rework this a bit to talk about the example and explain at the start that this is what we're going to be deploying etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I added a phrase at the start of the console section to describe the example we're going to deploy and a phrase here in the "Invoke" section to describe the test event
|
||
The response of the invocation and additional meta data appears in the green section of the page. | ||
|
||
I can see the response from the Swift code: `Hello Swift on Lambda`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a mix or first person singular, first person plural and third person in the tutorial. We should align this for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
corrected
|
||
The function consumed 109.60ms of execution time, out of this 83.72ms where spent to initialize this new runtime. This initialization time is known as Lambda cold start time. | ||
|
||
> Lambda cold start time refers to the initial delay that occurs when a Lambda function is invoked for the first time or after being idle for a while. Cold starts happen because AWS needs to provision and initialize a new container, load your code, and start your runtime environment (in this case, the Swift runtime). This delay is particularly noticeable for the first invocation, but subsequent invocations (known as "warm starts") are typically much faster because the container and runtime are already initialized and ready to process requests. Cold starts are an important consideration when architecting serverless applications, especially for latency-sensitive workloads. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth adding a note here about how Swift compares to other languages for cold start times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually, compiled languages, such as Swift, Go, and Rust, have shorter cold start times compared to interpreted languages, such as Python, Java, Ruby, and Node.js.
done
|
||
To create a function, you must first create the function execution role and define the permission. Then, you create the function with the `create-function` command. | ||
|
||
The command assumes you've already created the ZIP file with the `swift package archive --allow-network-connections docker` command. The name and the path of the ZIP file depends on the executable target name you entered in the `Package.swift` file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or similar
The command assumes you've already created the ZIP file with the `swift package archive --allow-network-connections docker` command. The name and the path of the ZIP file depends on the executable target name you entered in the `Package.swift` file. | |
The command assumes you've already created the ZIP file with the `swift package archive --allow-network-connections docker` command. The name and the path of the ZIP file depends on the executable target name you entered in the `Package.swift` file. In this example, we're building the HelloWorld example from the examples directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this example, we're building the HelloWorld example from the Examples directory.
done
|
||
The `--architectures` flag is only required when you build the binary on an Apple Silicon machine (Apple M1 or more recent). It defaults to `x64`. | ||
|
||
To update the function, use the `update-function-code` command. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To update the function, use the `update-function-code` command. | |
To update the function, use the `update-function-code` command, once you've archived the updated code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To update the function, use the
update-function-code
command after you've recompiled and archived your code again with theswift package archive
command.
done
|
||
In this example, the Lambda function must accept an APIGateway v2 JSON payload as input parameter and return a valid APIGAteway v2 JSON response. See the example code in the [APIGateway example README file](https://github.com/swift-server/swift-aws-lambda-runtime/blob/main/Examples/APIGateway/README.md). | ||
|
||
To deploy the function with SAM, use the `sam deploy` command. The very first time you deploy a function, you must use the `--guided` flag to configure the deployment. The command will ask you a series of questions to configure the deployment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to do it if you provide all the flags right?
To deploy the function with SAM, use the `sam deploy` command. The very first time you deploy a function, you must use the `--guided` flag to configure the deployment. The command will ask you a series of questions to configure the deployment. | |
To deploy the function with SAM, use the `sam deploy` command. The very first time you deploy a function, you should use the `--guided` flag to configure the deployment. The command will ask you a series of questions to configure the deployment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Outputs | ||
-------------------------------------------------------------------------------- | ||
Key APIGatewayEndpoint | ||
Description API Gateway endpoint UR" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description API Gateway endpoint UR" | |
Description API Gateway endpoint URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
} | ||
``` | ||
The code assumes you already built the Swift Lambda function with the `swift package archive --allow-network-connections docker` command. The ZIP file is located in the `.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/MyLambda.zip` folder. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again we should be clear about what app we're deploying here so there's no confusion when invoking the lambda etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, I added a phrase at the start of the section and clarified this one.
e1630cd
to
5447fbf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
As discussed with @0xTim
This PR
Deployment.md
Swift Docc file to cover deployment with the AWS console, CLI, SAM, and CDK. It mentions and contains a call to contributions to further examples for third-party tools such as the Serverless Framework, Terraform, or Pulumi.