Skip to content

Commit 36dadf9

Browse files
authored
[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.
1 parent 9287d56 commit 36dadf9

File tree

6 files changed

+137
-60
lines changed

6 files changed

+137
-60
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ Package.resolved
1212
.vscode
1313
Makefile
1414
.devcontainer
15-
.amazonq
15+
.amazonq
16+
.kiro
17+
nodejs

Sources/AWSLambdaRuntime/Docs.docc/Deployment.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Learn how to deploy your Swift Lambda functions to AWS.
44

5+
### Overview
6+
57
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.
68

79
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:
1921
* [Deploy your Lambda function with AWS Cloud Development Kit (CDK)](#deploy-your-lambda-function-with-aws-cloud-development-kit-cdk)
2022
* [Third-party tools](#third-party-tools)
2123

22-
## Prerequisites
24+
### Prerequisites
2325

2426
1. Your AWS Account
2527

@@ -71,29 +73,29 @@ Here is the content of this guide:
7173
>[!NOTE]
7274
> 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.
7375
74-
## Choosing the AWS Region where to deploy
76+
### Choosing the AWS Region where to deploy
7577

7678
[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.
7779

7880
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.
7981

8082
Geographical compliance, also known as data residency compliance, involves following location-specific regulations about how and where data can be stored and processed.
8183

82-
## The Lambda execution IAM role
84+
### The Lambda execution IAM role
8385

8486
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.
8587

8688
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.
8789

88-
## Deploy your Lambda function with the AWS Console
90+
### Deploy your Lambda function with the AWS Console
8991

9092
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`.
9193

9294
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.
9395

9496
![Console - Select AWS Region](console-10-regions)
9597

96-
### Create the function
98+
#### Create the function
9799

98100
Select **Create a function** to create a function.
99101

@@ -118,7 +120,7 @@ Select **Save**
118120

119121
You're now ready to test your function.
120122

121-
### Invoke the function
123+
#### Invoke the function
122124

123125
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`.
124126

@@ -150,7 +152,7 @@ REPORT RequestId: f789fbb6-10d9-4ba3-8a84-27aa283369a2 Duration: 1.12 ms Billed
150152

151153
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.
152154

153-
### Delete the function
155+
#### Delete the function
154156

155157
When you're finished with testing, you can delete the Lambda function and the IAM execution role that the console created automatically.
156158

@@ -164,13 +166,13 @@ Select the `HelloWorld-role-xxxx` role and select **Delete**. Confirm the deleti
164166

165167
![Console - delete IAM role](console-80-delete-role)
166168

167-
## Deploy your Lambda function with the AWS Command Line Interface (CLI)
169+
### Deploy your Lambda function with the AWS Command Line Interface (CLI)
168170

169171
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.
170172

171173
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.
172174

173-
### Create the function
175+
#### Create the function
174176

175177
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.
176178

@@ -245,7 +247,7 @@ aws lambda update-function-code \
245247
--zip-file fileb://.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/MyLambda.zip
246248
```
247249

248-
### Invoke the function
250+
#### Invoke the function
249251

250252
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.
251253

@@ -263,7 +265,7 @@ cat out.txt
263265
rm out.txt
264266
```
265267

266-
### Delete the function
268+
#### Delete the function
267269

268270
To cleanup, first delete the Lambda funtion, then delete the IAM role.
269271

@@ -278,15 +280,15 @@ aws iam delete-role-policy --role-name lambda_basic_execution --policy-name lamb
278280
aws iam delete-role --role-name lambda_basic_execution
279281
```
280282

281-
## Deploy your Lambda function with AWS Serverless Application Model (SAM)
283+
### Deploy your Lambda function with AWS Serverless Application Model (SAM)
282284

283285
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.
284286

285287
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.
286288

287289
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.
288290

289-
### Create the function
291+
#### Create the function
290292

291293
We assume your Swift function is compiled and packaged, as described in the [Prerequisites](#prerequisites) section.
292294

@@ -375,7 +377,7 @@ Successfully created/updated stack - APIGAtewayLambda in us-east-1
375377
376378
To update your function or any other AWS service defined in your YAML file, you can use the `sam deploy` command without the `--guided` flag.
377379
378-
### Invoke the function
380+
#### Invoke the function
379381
380382
SAM allows you to invoke the function locally and remotely.
381383
@@ -427,7 +429,7 @@ Access logging is disabled for HTTP API ID (g9m53sn7xa)
427429
428430
You can also tail the logs with the `-t, --tail` flag.
429431
430-
### Delete the function
432+
#### Delete the function
431433
432434
SAM allows you to delete your function and all infrastructure that is defined in the YAML template with just one command.
433435
@@ -443,7 +445,7 @@ Are you sure you want to delete the folder APIGatewayLambda in S3 which contains
443445
Deleted successfully
444446
```
445447
446-
## Deploy your Lambda function with the AWS Cloud Development Kit (CDK)
448+
### Deploy your Lambda function with the AWS Cloud Development Kit (CDK)
447449
448450
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.
449451
@@ -453,7 +455,7 @@ Use the CDK when you want to define your infrastructure in code and manage the d
453455
454456
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.
455457
456-
### Create a CDK project
458+
#### Create a CDK project
457459
458460
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.
459461
@@ -523,7 +525,7 @@ import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations
523525
// ...
524526
```
525527
526-
### Deploy the infrastructure
528+
#### Deploy the infrastructure
527529
528530
To deploy the infrastructure, type the following commands.
529531
@@ -553,7 +555,7 @@ arn:aws:cloudformation:eu-central-1:012345678901:stack/LambdaApiStack/e0054390-b
553555
✨ Total time: 45.84s
554556
```
555557
556-
### Invoke your Lambda function
558+
#### Invoke your Lambda function
557559
558560
To invoke the Lambda function, use this `curl` command line.
559561
@@ -609,7 +611,7 @@ curl -s https://tyqnjcawh0.execute-api.eu-central-1.amazonaws.com | jq
609611
}
610612
```
611613
612-
### Delete the infrastructure
614+
#### Delete the infrastructure
613615
614616
When done testing, you can delete the infrastructure with this command.
615617
@@ -622,6 +624,6 @@ LambdaApiStack: destroying... [1/1]
622624
✅ LambdaApiStack: destroyed
623625
```
624626
625-
## Third-party tools
627+
### Third-party tools
626628
627629
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

Comments
 (0)