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: Examples/Testing/README.md
+9-8
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ In this document, we describe four different testing strategies:
10
10
*[Local invocation using the AWS SAM CLI](#local-invocation-using-the-aws-sam-cli)
11
11
12
12
> [!IMPORTANT]
13
-
> In this example, the API Gateway sends a payload to the Lambda function as a JSON string. Your business payload is in the `body` section of the API Gateway payload. It is base64-encoded. You can find an example of the API Gateway payload in the `event.json` file. The API Gateway event format is documented in [Create AWS Lambda proxy integrations for HTTP APIs in API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html).
13
+
> In this example, the API Gateway sends an event to your Lambda function as a JSON string. Your business payload is in the `body` section of the API Gateway event. It is base64-encoded. You can find an example of the API Gateway event in the `event.json` file. The API Gateway event format is documented in [Create AWS Lambda proxy integrations for HTTP APIs in API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html).
14
14
15
15
To include a sample event in your test targets, you must add the `event.json` file from the `Tests` directory to the binary bundle. To do so, add a `resources` section in your `Package.swift` file:
2. Add a test target to your `Package.swift` file.
53
54
```swift
@@ -62,7 +63,7 @@ class BusinessTests {
62
63
63
64
## Integration Testing the handler function
64
65
65
-
You can test the handler function by creating an input event, a mock Lambda context, and calling the handler function from your test.
66
+
You can test the handler function by creating an input event, a mock Lambda context, and calling your Lambda handler function from your test.
66
67
Your Lambda handler function must be declared separatly from the `LambdaRuntime`. For example:
67
68
68
69
```swift
@@ -131,9 +132,9 @@ public struct HandlerTest {
131
132
132
133
You can test your Lambda function locally by invoking it with the Swift AWS Lambda Runtime.
133
134
134
-
You must pass a payload to the Lambda function. You can use the `Tests/event.json` file for this purpose. The return value is a `APIGatewayV2Response` object in this example.
135
+
You must pass an event to the Lambda function. You can use the `Tests/event.json` file for this purpose. The return value is a `APIGatewayV2Response` object in this example.
135
136
136
-
Just type `swift run` to run the Lambda function locally.
137
+
Just type `swift run` to run the Lambda function locally, this starts a local HTTP endpoint on localhost:7000.
137
138
138
139
```sh
139
140
LOG_LEVEL=trace swift run
@@ -151,9 +152,9 @@ This returns the following response:
151
152
152
153
## Local invocation using the AWS SAM CLI
153
154
154
-
The AWS SAM CLI provides you with a local testing environment for your Lambda functions. It deploys and invoke your function locally in a Docker container designed to mimic the AWS Lambda environment.
155
+
The AWS SAM CLI provides you with a local testing environment for your Lambda functions. It deploys and invokes your function locally in a Docker container designed to mimic the AWS Lambda environment.
155
156
156
-
You must pass a payload to the Lambda function. You can use the `event.json` file for this purpose. The return value is a `APIGatewayV2Response` object in this example.
157
+
You must pass an event to the Lambda function. You can use the `event.json` file for this purpose. The return value is a `APIGatewayV2Response` object in this example.
157
158
158
159
```sh
159
160
sam local invoke -e Tests/event.json
@@ -167,4 +168,4 @@ END RequestId: 5b71587a-39da-445e-855d-27a700e57efd
167
168
REPORT RequestId: 5b71587a-39da-445e-855d-27a700e57efd Init Duration: 0.04 ms Duration: 21.57 ms Billed Duration: 22 ms Memory Size: 512 MB Max Memory Used: 512 MB
168
169
169
170
{"body": "Hello world of swift lambda!", "statusCode": 200, "headers": {"content-type": "application/json"}}
0 commit comments