Skip to content

Commit e3929db

Browse files
committed
Add SoS metadata and readme
1 parent 9bad867 commit e3929db

File tree

3 files changed

+191
-11
lines changed

3 files changed

+191
-11
lines changed

.doc_gen/metadata/lambda_metadata.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ lambda_CreateFunction:
172172
- snippet_tags:
173173
- lambda.rust.scenario.create_function
174174
- lambda.rust.scenario.prepare_function
175+
Swift:
176+
versions:
177+
- sdk_version: 1
178+
github: swift/example_code/lambda/basics
179+
excerpts:
180+
- description:
181+
snippet_tags:
182+
- swift.lambda-basics.imports
183+
- swift.lambda-basics.CreateFunction
175184
services:
176185
lambda: {CreateFunction}
177186
lambda_DeleteFunction:
@@ -380,6 +389,15 @@ lambda_Invoke:
380389
- snippet_tags:
381390
- lambda.rust.scenario.invoke
382391
- lambda.rust.scenario.log_invoke_output
392+
Swift:
393+
versions:
394+
- sdk_version: 1
395+
github: swift/example_code/lambda/basics
396+
excerpts:
397+
- description:
398+
snippet_tags:
399+
- swift.lambda-basics.imports
400+
- swift.lambda-basics.Invoke
383401
services:
384402
lambda: {Invoke}
385403
lambda_GetFunction:
@@ -474,6 +492,15 @@ lambda_GetFunction:
474492
excerpts:
475493
- snippet_tags:
476494
- lambda.rust.scenario.get_function
495+
Swift:
496+
versions:
497+
- sdk_version: 1
498+
github: swift/example_code/lambda/basics
499+
excerpts:
500+
- description:
501+
snippet_tags:
502+
- swift.lambda-basics.imports
503+
- swift.lambda-basics.GetFunctionInput
477504
services:
478505
lambda: {GetFunction}
479506
lambda_UpdateFunctionCode:
@@ -569,6 +596,15 @@ lambda_UpdateFunctionCode:
569596
- snippet_tags:
570597
- lambda.rust.scenario.update_function_code
571598
- lambda.rust.scenario.prepare_function
599+
Swift:
600+
versions:
601+
- sdk_version: 1
602+
github: swift/example_code/lambda/basics
603+
excerpts:
604+
- description:
605+
snippet_tags:
606+
- swift.lambda-basics.imports
607+
- swift.lambda-basics.UpdateFunctionCode
572608
services:
573609
lambda: {UpdateFunctionCode}
574610
lambda_UpdateFunctionConfiguration:
@@ -748,6 +784,15 @@ lambda_ListFunctions:
748784
excerpts:
749785
- snippet_tags:
750786
- lambda.rust.scenario.list_functions
787+
Swift:
788+
versions:
789+
- sdk_version: 1
790+
github: swift/example_code/lambda/basics
791+
excerpts:
792+
- description:
793+
snippet_tags:
794+
- swift.lambda-basics.imports
795+
- swift.lambda-basics.ListFunctionsPaginated
751796
services:
752797
lambda: {ListFunctions}
753798
lambda_Scenario_GettingStartedFunctions:
@@ -937,5 +982,23 @@ lambda_Scenario_GettingStartedFunctions:
937982
This file is src/bin/scenario.rs in the crate.
938983
snippet_files:
939984
- rustv1/examples/lambda/src/bin/scenario.rs
985+
Swift:
986+
versions:
987+
- sdk_version: 1
988+
github: swift/example_code/lambda/basics
989+
excerpts:
990+
- description: Define the first &LAM; function, which simply increments the specified value.
991+
snippet_files:
992+
- swift/example_code/lambda/basics/increment/Package.swift
993+
- swift/example_code/lambda/basics/increment/Sources/increment.swift
994+
- description: Define the second &LAM; function, which performs an arithmetic operation on two numbers.
995+
snippet_files:
996+
- swift/example_code/lambda/basics/calculator/Package.swift
997+
- swift/example_code/lambda/basics/calculator/Sources/calculator.swift
998+
- description: Define the main program that will invoke the two &LAM; functions.
999+
snippet_files:
1000+
- swift/example_code/lambda/basics/lambda-basics/Package.swift
1001+
- swift/example_code/lambda/basics/lambda-basics/Sources/entry.swift
1002+
- swift/example_code/lambda/basics/lambda-basics/Sources/ExampleError.swift
9401003
services:
9411004
lambda: {CreateFunction, DeleteFunction, Invoke, GetFunction, ListFunctions, UpdateFunctionCode, UpdateFunctionConfiguration}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Lambda code examples for the SDK for Swift
2+
3+
## Overview
4+
5+
Shows how to use the AWS SDK for Swift to work with AWS Lambda.
6+
7+
<!--custom.overview.start-->
8+
<!--custom.overview.end-->
9+
10+
_Lambda allows you to run code without provisioning or managing servers._
11+
12+
## ⚠ Important
13+
14+
* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/) and [Free Tier](https://aws.amazon.com/free/).
15+
* Running the tests might result in charges to your AWS account.
16+
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege).
17+
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).
18+
19+
<!--custom.important.start-->
20+
<!--custom.important.end-->
21+
22+
## Code examples
23+
24+
### Prerequisites
25+
26+
For prerequisites, see the [README](../../README.md#Prerequisites) in the `swift` folder.
27+
28+
29+
<!--custom.prerequisites.start-->
30+
<!--custom.prerequisites.end-->
31+
32+
### Basics
33+
34+
Code examples that show you how to perform the essential operations within a service.
35+
36+
- [Learn the basics](basics/increment/Package.swift)
37+
38+
39+
### Single actions
40+
41+
Code excerpts that show you how to call individual service functions.
42+
43+
- [CreateFunction](basics/lambda-basics/Sources/entry.swift#L177)
44+
- [GetFunction](basics/lambda-basics/Sources/entry.swift#L142)
45+
- [Invoke](basics/lambda-basics/Sources/entry.swift#L313)
46+
- [ListFunctions](basics/lambda-basics/Sources/entry.swift#L283)
47+
- [UpdateFunctionCode](basics/lambda-basics/Sources/entry.swift#L236)
48+
49+
50+
<!--custom.examples.start-->
51+
<!--custom.examples.end-->
52+
53+
## Run the examples
54+
55+
### Instructions
56+
57+
To build any of these examples from a terminal window, navigate into its
58+
directory, then use the following command:
59+
60+
```
61+
$ swift build
62+
```
63+
64+
To build one of these examples in Xcode, navigate to the example's directory
65+
Then type `xed.` to open the example directory in Xcode. You can then use
66+
standard Xcode build and run commands.
67+
68+
<!--custom.instructions.start-->
69+
<!--custom.instructions.end-->
70+
71+
72+
#### Learn the basics
73+
74+
This example shows you how to do the following:
75+
76+
- Create an IAM role and Lambda function, then upload handler code.
77+
- Invoke the function with a single parameter and get results.
78+
- Update the function code and configure with an environment variable.
79+
- Invoke the function with new parameters and get results. Display the returned execution log.
80+
- List the functions for your account, then clean up resources.
81+
82+
<!--custom.basic_prereqs.lambda_Scenario_GettingStartedFunctions.start-->
83+
<!--custom.basic_prereqs.lambda_Scenario_GettingStartedFunctions.end-->
84+
85+
86+
<!--custom.basics.lambda_Scenario_GettingStartedFunctions.start-->
87+
<!--custom.basics.lambda_Scenario_GettingStartedFunctions.end-->
88+
89+
90+
### Tests
91+
92+
⚠ Running tests might result in charges to your AWS account.
93+
94+
95+
To find instructions for running these tests, see the [README](../../README.md#Tests)
96+
in the `swift` folder.
97+
98+
99+
100+
<!--custom.tests.start-->
101+
<!--custom.tests.end-->
102+
103+
## Additional resources
104+
105+
- [Lambda Developer Guide](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)
106+
- [Lambda API Reference](https://docs.aws.amazon.com/lambda/latest/dg/API_Reference.html)
107+
- [SDK for Swift Lambda reference](https://sdk.amazonaws.com/swift/api/awslambda/latest/documentation/awslambda)
108+
109+
<!--custom.resources.start-->
110+
<!--custom.resources.end-->
111+
112+
---
113+
114+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
115+
116+
SPDX-License-Identifier: Apache-2.0

swift/example_code/lambda/basics/lambda-basics/Sources/entry.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
/// An example that demonstrates how to watch an transcribe event stream to
55
/// transcribe audio from a file to the console.
66

7-
// snippet-start:[swift.lambda-basics.imports]
7+
// snippet-start:[swift.lambda-basics.imports-all]
88
import ArgumentParser
9-
import AWSClientRuntime
109
import AWSIAM
10+
import SmithyWaitersAPI
11+
// snippet-start:[swift.lambda-basics.imports]
12+
import AWSClientRuntime
1113
import AWSLambda
1214
import Foundation
13-
import SmithyWaitersAPI
1415
// snippet-end:[swift.lambda-basics.imports]
16+
// snippet-end:[swift.lambda-basics.imports-all]
1517

1618
// snippet-start:[swift.lambda-basics.InvokeInput.types]
1719
/// Represents the contents of the requests being received from the client.
@@ -157,7 +159,7 @@ struct ExampleCommand: ParsableCommand {
157159

158160
return true
159161
}
160-
// snippet-start:[swift.lambda-basics.GetFunctionInput]
162+
// snippet-end:[swift.lambda-basics.GetFunctionInput]
161163

162164
// snippet-start:[swift.lambda-basics.CreateFunction.wait]
163165
/// Create the specified AWS Lambda function.
@@ -193,7 +195,6 @@ struct ExampleCommand: ParsableCommand {
193195
)
194196
)
195197
} catch {
196-
dump(error)
197198
return false
198199
}
199200
// snippet-end:[swift.lambda-basics.CreateFunction]
@@ -218,7 +219,7 @@ struct ExampleCommand: ParsableCommand {
218219
}
219220
// snippet-end:[swift.lambda-basics.CreateFunction.wait]
220221

221-
// snippet-start:[swift.lambda-basics.UpdateFunction.wait]
222+
// snippet-start:[swift.lambda-basics.UpdateFunctionCode.wait]
222223
/// Update the AWS Lambda function with new code to run when the function
223224
/// is invoked.
224225
///
@@ -232,7 +233,7 @@ struct ExampleCommand: ParsableCommand {
232233
/// Otherwise, returns `false`.
233234
func updateFunctionCode(lambdaClient: LambdaClient, name: String,
234235
path: String) async throws -> Bool {
235-
// snippet-start:[swift.lambda-basics.UpdateFunction]
236+
// snippet-start:[swift.lambda-basics.UpdateFunctionCode]
236237
let zipUrl = URL(fileURLWithPath: path)
237238
let zipData: Data
238239

@@ -257,7 +258,7 @@ struct ExampleCommand: ParsableCommand {
257258
} catch {
258259
return false
259260
}
260-
// snippet-start:[swift.lambda-basics.UpdateFunction.wait]
261+
// snippet-end:[swift.lambda-basics.UpdateFunctionCode]
261262

262263
let output = try await lambdaClient.waitUntilFunctionUpdatedV2(
263264
options: WaiterOptions(
@@ -277,7 +278,7 @@ struct ExampleCommand: ParsableCommand {
277278
return false
278279
}
279280
}
280-
// snippet-end:[swift.lambda-basics.UpdateFunction.wait]
281+
// snippet-end:[swift.lambda-basics.UpdateFunctionCode.wait]
281282

282283
// snippet-start:[swift.lambda-basics.ListFunctionsPaginated]
283284
/// Returns an array containing the names of all AWS Lambda functions
@@ -309,7 +310,7 @@ struct ExampleCommand: ParsableCommand {
309310
}
310311
// snippet-end:[swift.lambda-basics.ListFunctionsPaginated]
311312

312-
// snippet-start:[swift.lambda-basics.InvokeInput]
313+
// snippet-start:[swift.lambda-basics.Invoke]
313314
/// Invoke the Lambda function to increment a value.
314315
///
315316
/// - Parameters:
@@ -344,7 +345,7 @@ struct ExampleCommand: ParsableCommand {
344345
throw ExampleError.invokeError
345346
}
346347
}
347-
// snippet-end:[swift.lambda-basics.InvokeInput]
348+
// snippet-end:[swift.lambda-basics.Invoke]
348349

349350
/// Invoke the calculator Lambda function.
350351
///

0 commit comments

Comments
 (0)