Skip to content

Commit 50e510b

Browse files
committed
Switch to standard Foundation
1 parent 32b7459 commit 50e510b

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

Examples/S3EventNotifier/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This example demonstrates how to write a Lambda that is invoked by an event orig
44

55
## Code
66

7-
In this example the lambda function receives an `S3Event` object defined in the `AWSLambdaEvents` library as input object. The `S3Event` object contains all the information about the S3 event that triggered the function, but what we are interested in is the bucket name and the object key, which are inside of a notification `Record`. The object contains an array of records, however since the lambda is triggered by a single event, we can safely assume that there is only one record in the array: the first one. Inside of this record, we can find the bucket name and the object key:
7+
In this example the Lambda function receives an `S3Event` object defined in the `AWSLambdaEvents` library as input object. The `S3Event` object contains all the information about the S3 event that triggered the function, but what we are interested in is the bucket name and the object key, which are inside of a notification `Record`. The object contains an array of records, however since the Lambda function is triggered by a single event, we can safely assume that there is only one record in the array: the first one. Inside of this record, we can find the bucket name and the object key:
88

99
```swift
1010
guard let s3NotificationRecord = event.records.first else {
@@ -46,13 +46,13 @@ The `--architectures` flag is only required when you build the binary on an Appl
4646

4747
Be sure to replace `<YOUR_ACCOUNT_ID>` with your actual AWS account ID (for example: 012345678901).
4848

49-
Besides deploying the lambda function you also need to create the S3 bucket and configure it to send events to the lambda function. You can do this using the following commands:
49+
Besides deploying the Lambda function you also need to create the S3 bucket and configure it to send events to the Lambda function. You can do this using the following commands:
5050

5151
```bash
5252
aws s3api create-bucket --bucket my-test-bucket --region eu-west-1 --create-bucket-configuration LocationConstraint=eu-west-1
5353

5454
aws lambda add-permission \
55-
--function-name ProcessS3Upload \
55+
--function-name S3EventNotifier \
5656
--statement-id S3InvokeFunction \
5757
--action lambda:InvokeFunction \
5858
--principal s3.amazonaws.com \
@@ -62,7 +62,7 @@ aws s3api put-bucket-notification-configuration \
6262
--bucket my-test-bucket \
6363
--notification-configuration '{
6464
"LambdaFunctionConfigurations": [{
65-
"LambdaFunctionArn": "arn:aws:lambda:<REGION>:<YOUR_ACCOUNT_ID>:function:ProcessS3Upload",
65+
"LambdaFunctionArn": "arn:aws:lambda:<REGION>:<YOUR_ACCOUNT_ID>:function:S3EventNotifier",
6666
"Events": ["s3:ObjectCreated:*"]
6767
}]
6868
}'
@@ -72,8 +72,8 @@ aws s3 cp testfile.txt s3://my-test-bucket/
7272

7373
This will:
7474
- create a bucket named `my-test-bucket` in the `eu-west-1` region;
75-
- add a permission to the lambda function to be invoked by the bucket;
76-
- configure the bucket to send `s3:ObjectCreated:*` events to the lambda function named `ProcessS3Upload`;
75+
- add a permission to the Lambda function to be invoked by Amazon S3;
76+
- configure the bucket to send `s3:ObjectCreated:*` events to the Lambda function named `S3EventNotifier`;
7777
- upload a file named `testfile.txt` to the bucket.
7878

79-
Replace `<REGION>` with the region where you deployed the lambda function and `<YOUR_ACCOUNT_ID>` with your actual AWS account ID.
79+
Replace `<REGION>` with the region where you deployed the Lambda function and `<YOUR_ACCOUNT_ID>` with your actual AWS account ID.

Examples/S3EventNotifier/Sources/main.swift

-7
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,9 @@
1414

1515
import AWSLambdaEvents
1616
import AWSLambdaRuntime
17-
18-
#if canImport(FoundationEssentials)
19-
import FoundationEssentials
20-
#else
2117
import Foundation
22-
#endif
2318

2419
let runtime = LambdaRuntime { (event: S3Event, context: LambdaContext) async throws in
25-
context.logger.debug("Received S3 event: \(event)")
26-
2720
guard let s3NotificationRecord = event.records.first else {
2821
context.logger.error("No S3 notification record found in the event")
2922
return

0 commit comments

Comments
 (0)