Skip to content

Add S3EventNotifier example #477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 11, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Examples/S3EventNotifier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ If there are no errors, a ZIP file should be ready to deploy, located at `.build

## Deploy

[!IMPORTANT]
The Lambda function and the S3 bucket must be located in the same AWS Region. In the code below, we use `eu-west-1` (Ireland).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think GH markdown requires this to be in block quotes, so

> [!IMPORTANT]
> The Lambda function...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct - thank you


To deploy the Lambda function, you can use the `aws` command line:

```bash
aws lambda create-function \
--region eu-west-1 \
--function-name S3EventNotifier \
--zip-file fileb://.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/S3EventNotifier/S3EventNotifier.zip \
--runtime provided.al2 \
Expand All @@ -51,14 +55,16 @@ Besides deploying the Lambda function you also need to create the S3 bucket and
```bash
aws s3api create-bucket --bucket my-test-bucket --region eu-west-1 --create-bucket-configuration LocationConstraint=eu-west-1

aws lambda add-permission \
aws lambda add-permission
--region eu-west-1 \
--function-name S3EventNotifier \
--statement-id S3InvokeFunction \
--action lambda:InvokeFunction \
--principal s3.amazonaws.com \
--source-arn arn:aws:s3:::my-test-bucket

aws s3api put-bucket-notification-configuration \
--region eu-west-1 \
--bucket my-test-bucket \
--notification-configuration '{
"LambdaFunctionConfigurations": [{
Expand All @@ -67,7 +73,7 @@ aws s3api put-bucket-notification-configuration \
}]
}'

aws s3 cp testfile.txt s3://my-test-bucket/
touch testfile.txt && aws s3 cp testfile.txt s3://my-test-bucket/
```

This will:
Expand All @@ -76,4 +82,7 @@ This will:
- configure the bucket to send `s3:ObjectCreated:*` events to the Lambda function named `S3EventNotifier`;
- upload a file named `testfile.txt` to the bucket.

Replace `<REGION>` with the region where you deployed the Lambda function and `<YOUR_ACCOUNT_ID>` with your actual AWS account ID.
Replace `my-test-bucket` with your bucket name (bucket names are unique globaly and this one is already taken). Also replace `<REGION>` with the region where you deployed the Lambda function and `<YOUR_ACCOUNT_ID>` with your actual AWS account ID.

[!IMPORTANT]
The Lambda function and the S3 bucket must be located in the same AWS Region. Adjust the code above according to your closest AWS Region.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be unnecessary if we have the one above already? But I'm not precious about it. If you do end up leaving it, this should use block quotes too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it on purpose - it so important and I'm sure so many will not read it :-)