# Amazon S3 bucket notifications to AWS Lambda This pattern creates an Amazon S3 bucket, AWS Lambda function and setup S3 bucket event notifications to trigger the Lambda function. In this example, notifications with type `s3:ObjectCreated:*`, filter prefix (`data/`) and suffix (`.json`) are configured. ## Getting started with Terraform Serverless Patterns Read more about general requirements and deployment instructions for Terraform Serverless Patterns [here](https://github.com/aws-samples/serverless-patterns/blob/main/terraform-fixtures/docs/README.md). ## Testing After deployment, upload file to the S3 bucket. Make sure that file matches filter prefix and suffix to trigger a notification. Go to the CloudWatch Logs for the deployed Lambda function. You will see the event is logged out containing the item data. To do this, you can run these commands in the terminal (replace `` with the value returned in `s3_bucket_id`): ```shell echo "Test file" > test.json aws s3 cp test.json s3:///data/ ``` ## Requirements | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.0 | | [aws](#requirement\_aws) | >= 4.9 | | [random](#requirement\_random) | >= 2.0 | ## Providers | Name | Version | |------|---------| | [random](#provider\_random) | >= 2.0 | ## Modules | Name | Source | Version | |------|--------|---------| | [lambda\_function](#module\_lambda\_function) | terraform-aws-modules/lambda/aws | ~> 4.0 | | [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 3.0 | | [s3\_notification](#module\_s3\_notification) | terraform-aws-modules/s3-bucket/aws//modules/notification | ~> 3.0 | ## Resources | Name | Type | |------|------| | [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource | ## Inputs No inputs. ## Outputs | Name | Description | |------|-------------| | [lambda\_function\_arn](#output\_lambda\_function\_arn) | The ARN of the Lambda Function | | [lambda\_function\_invoke\_arn](#output\_lambda\_function\_invoke\_arn) | The Invoke ARN of the Lambda Function | | [lambda\_function\_name](#output\_lambda\_function\_name) | The name of the Lambda Function | | [lambda\_function\_qualified\_arn](#output\_lambda\_function\_qualified\_arn) | The ARN identifying your Lambda Function Version | | [lambda\_function\_version](#output\_lambda\_function\_version) | Latest published version of Lambda Function | | [lambda\_role\_arn](#output\_lambda\_role\_arn) | The ARN of the IAM role created for the Lambda Function | | [s3\_bucket\_arn](#output\_s3\_bucket\_arn) | The ARN of the bucket. Will be of format arn:aws:s3:::bucketname. | | [s3\_bucket\_id](#output\_s3\_bucket\_id) | The name of the bucket. |