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
[doc] fix header level warnings from CI soundness/doc scripts (#537)
```
note: The majority of content should be under level-3 headers under the "Overview" section
--> Deployment.md:22:1-22:17
20 | * [Third-party tools](#third-party-tools)
21 |
22 + ## Prerequisites
| ╰─suggestion: Change the title to "Overview"
23 |
24 | 1. Your AWS Account
```
and many others.
Action: I lowered all titles one level down.
Copy file name to clipboardExpand all lines: Sources/AWSLambdaRuntime/Docs.docc/Deployment.md
+23-21Lines changed: 23 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
Learn how to deploy your Swift Lambda functions to AWS.
4
4
5
+
### Overview
6
+
5
7
There are multiple ways to deploy your Swift code to AWS Lambda. The very first time, you'll probably use the AWS Console to create a new Lambda function and upload your code as a zip file. However, as you iterate on your code, you'll want to automate the deployment process.
6
8
7
9
To take full advantage of the cloud, we recommend using Infrastructure as Code (IaC) tools like the [AWS Serverless Application Model (SAM)](https://aws.amazon.com/serverless/sam/) or [AWS Cloud Development Kit (CDK)](https://aws.amazon.com/cdk/). These tools allow you to define your infrastructure and deployment process as code, which can be version-controlled and automated.
@@ -19,7 +21,7 @@ Here is the content of this guide:
19
21
*[Deploy your Lambda function with AWS Cloud Development Kit (CDK)](#deploy-your-lambda-function-with-aws-cloud-development-kit-cdk)
20
22
*[Third-party tools](#third-party-tools)
21
23
22
-
## Prerequisites
24
+
###Prerequisites
23
25
24
26
1. Your AWS Account
25
27
@@ -71,29 +73,29 @@ Here is the content of this guide:
71
73
>[!NOTE]
72
74
> When building on Linux, your current user must have permission to use docker. On most Linux distributions, you can do so by adding your user to the `docker` group with the following command: `sudo usermod -aG docker $USER`. You must log out and log back in for the changes to take effect.
73
75
74
-
## Choosing the AWS Region where to deploy
76
+
###Choosing the AWS Region where to deploy
75
77
76
78
[AWS Global infrastructure](https://aws.amazon.com/about-aws/global-infrastructure/) spans over 34 geographic Regions (and continuously expanding). When you create a resource on AWS, such as a Lambda function, you have to select a geographic region where the resource will be created. The two main factors to consider to select a Region are the physical proximity with your users and geographical compliance.
77
79
78
80
Physical proximity helps you reduce the network latency between the Lambda function and your customers. For example, when the majority of your users are located in South-East Asia, you might consider deploying in the Singapore, the Malaysia, or Jakarta Region.
79
81
80
82
Geographical compliance, also known as data residency compliance, involves following location-specific regulations about how and where data can be stored and processed.
81
83
82
-
## The Lambda execution IAM role
84
+
###The Lambda execution IAM role
83
85
84
86
A Lambda execution role is an AWS Identity and Access Management (IAM) role that grants your Lambda function the necessary permissions to interact with other AWS services and resources. Think of it as a security passport that determines what your function is allowed to do within AWS. For example, if your Lambda function needs to read files from Amazon S3, write logs to Amazon CloudWatch, or access an Amazon DynamoDB table, the execution role must include the appropriate permissions for these actions.
85
87
86
88
When you create a Lambda function, you must specify an execution role. This role contains two main components: a trust policy that allows the Lambda service itself to assume the role, and permission policies that determine what AWS resources the function can access. By default, Lambda functions get basic permissions to write logs to CloudWatch Logs, but any additional permissions (like accessing S3 buckets or sending messages to SQS queues) must be explicitly added to the role's policies. Following the principle of least privilege, it's recommended to grant only the minimum permissions necessary for your function to operate, helping maintain the security of your serverless applications.
87
89
88
-
## Deploy your Lambda function with the AWS Console
90
+
###Deploy your Lambda function with the AWS Console
89
91
90
92
In this section, we deploy the HelloWorld example function using the AWS Console. The HelloWorld function is a simple function that takes a `String` as input and returns a `String`.
91
93
92
94
Authenticate on the AWS console using your IAM username and password. On the top right side, select the AWS Region where you want to deploy, then navigate to the Lambda section.
Select **Create a function** to create a function.
99
101
@@ -118,7 +120,7 @@ Select **Save**
118
120
119
121
You're now ready to test your function.
120
122
121
-
### Invoke the function
123
+
####Invoke the function
122
124
123
125
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. As explained, the function takes a `String` as input and returns a `String`. we will therefore create a test event with a JSON payload that contains a `String`.
AWS lambda charges usage per number of invocations and the CPU time, rounded to the next millisecond. AWS Lambda offers a generous free-tier of 1 million invocation each month and 400,000 GB-seconds of compute time per month. See [Lambda pricing](https://aws.amazon.com/lambda/pricing/) for the details.
152
154
153
-
### Delete the function
155
+
####Delete the function
154
156
155
157
When you're finished with testing, you can delete the Lambda function and the IAM execution role that the console created automatically.
156
158
@@ -164,13 +166,13 @@ Select the `HelloWorld-role-xxxx` role and select **Delete**. Confirm the deleti
164
166
165
167

166
168
167
-
## Deploy your Lambda function with the AWS Command Line Interface (CLI)
169
+
###Deploy your Lambda function with the AWS Command Line Interface (CLI)
168
170
169
171
You can deploy your Lambda function using the AWS Command Line Interface (CLI). The CLI is a unified tool to manage your AWS services from the command line and automate your operations through scripts. The CLI is available for Windows, macOS, and Linux. Follow the [installation](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) and [configuration](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html) instructions in the AWS CLI User Guide.
170
172
171
173
In this example, we're building the HelloWorld example from the [Examples](https://github.com/swift-server/swift-aws-lambda-runtime/tree/main/Examples) directory.
172
174
173
-
### Create the function
175
+
####Create the function
174
176
175
177
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.
Use the `invoke-function` command to invoke the function. You can pass a well-formed JSON payload as input to the function. The payload must be encoded in base64. The CLI returns the status code and stores the response in a file.
251
253
@@ -263,7 +265,7 @@ cat out.txt
263
265
rm out.txt
264
266
```
265
267
266
-
### Delete the function
268
+
####Delete the function
267
269
268
270
To cleanup, first delete the Lambda funtion, then delete the IAM role.
aws iam delete-role --role-name lambda_basic_execution
279
281
```
280
282
281
-
## Deploy your Lambda function with AWS Serverless Application Model (SAM)
283
+
###Deploy your Lambda function with AWS Serverless Application Model (SAM)
282
284
283
285
AWS Serverless Application Model (SAM) is an open-source framework for building serverless applications. It provides a simplified way to define the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application. You can define your serverless application in a single file, and SAM will use it to deploy your function and all its dependencies.
284
286
285
287
To use SAM, you need to [install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) on your machine. The SAM CLI provides a set of commands to package, deploy, and manage your serverless applications.
286
288
287
289
Use SAM when you want to deploy more than a Lambda function. SAM helps you to create additional resources like an API Gateway, an S3 bucket, or a DynamoDB table, and manage the permissions between them.
288
290
289
-
### Create the function
291
+
####Create the function
290
292
291
293
We assume your Swift function is compiled and packaged, as described in the [Prerequisites](#prerequisites) section.
To update your functionor any other AWS service defined in your YAML file, you can use the `sam deploy`command without the `--guided` flag.
377
379
378
-
### Invoke the function
380
+
#### Invoke the function
379
381
380
382
SAM allows you to invoke the functionlocally and remotely.
381
383
@@ -427,7 +429,7 @@ Access logging is disabled for HTTP API ID (g9m53sn7xa)
427
429
428
430
You can also tail the logs with the `-t, --tail` flag.
429
431
430
-
### Delete the function
432
+
#### Delete the function
431
433
432
434
SAM allows you to delete your functionand all infrastructure that is defined in the YAML template with just one command.
433
435
@@ -443,7 +445,7 @@ Are you sure you want to delete the folder APIGatewayLambda in S3 which contains
443
445
Deleted successfully
444
446
```
445
447
446
-
## Deploy your Lambda function with the AWS Cloud Development Kit (CDK)
448
+
### Deploy your Lambda function with the AWS Cloud Development Kit (CDK)
447
449
448
450
The AWS Cloud Development Kit is an open-source software development framework to define cloud infrastructure in code and provision it through AWS CloudFormation. The CDK provides high-level constructs that preconfigure AWS resources with best practices, and you can use familiar programming languages like TypeScript, Javascript, Python, Java, C#, and Go to define your infrastructure.
449
451
@@ -453,7 +455,7 @@ Use the CDK when you want to define your infrastructure in code and manage the d
453
455
454
456
This example deploys the [APIGateway]((https://github.com/swift-server/swift-aws-lambda-runtime/blob/main/Examples/APIGateway/) example code. It comprises a Lambda function that implements a REST API and an API Gateway to expose the function over HTTPS.
455
457
456
-
### Create a CDK project
458
+
#### Create a CDK project
457
459
458
460
To create a new CDK project, use the `cdk init` command. The command creates a new directory with the project structure and the necessary files to define your infrastructure.
459
461
@@ -523,7 +525,7 @@ import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations
523
525
// ...
524
526
```
525
527
526
-
### Deploy the infrastructure
528
+
#### Deploy the infrastructure
527
529
528
530
To deploy the infrastructure, type the following commands.
We welcome contributions to this section. If you have experience deploying Swift Lambda functions with third-party tools like Serverless Framework, Terraform, or Pulumi, please share your knowledge with the community.
0 commit comments