Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions s3-lambda-terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lambda.zip
4 changes: 2 additions & 2 deletions s3-lambda-terraform/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# AWS S3 to AWS Lambda
# Amazon S3 to AWS Lambda
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: Fix to correct service name.


The Terraform template deploys a Lambda function, an S3 bucket and the IAM resources required to run the application. A Lambda function consumes <code>ObjectCreated</code> events from an Amazon S3 bucket. The Lambda code checks the uploaded file and console log the event.

Expand Down Expand Up @@ -57,7 +57,7 @@ After deployment, upload an object to the S3. Go to the CloudWatch Logs for the
```bash
terraform show
```
```
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Image


----
Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Expand Down
15 changes: 9 additions & 6 deletions s3-lambda-terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
version = "~> 5.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: Older version does not support Node.js 22 runtime. So I updated the version to v5.

}
random = {
source = "hashicorp/random"
Expand Down Expand Up @@ -32,7 +32,7 @@ resource "aws_lambda_function" "lambda_s3_handler" {
source_code_hash = data.archive_file.lambda_zip_file.output_base64sha256
handler = "index.handler"
role = aws_iam_role.iam_for_lambda.arn
runtime = "nodejs16.x"
runtime = "nodejs22.x"
}

data "archive_file" "lambda_zip_file" {
Expand All @@ -59,9 +59,13 @@ resource "aws_iam_role" "iam_for_lambda" {
]
}
EOF
inline_policy {
name = "lambda_logs_policy"
policy = <<EOF
}

resource "aws_iam_role_policy" "lambda_logs" {
name = "lambda_logs_policy"
role = aws_iam_role.iam_for_lambda.id

policy = <<EOF
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{
"Version": "2012-10-17",
"Statement": [
Expand All @@ -78,7 +82,6 @@ EOF
]
}
EOF
}
}

resource "aws_lambda_permission" "allow_bucket_invoke_lambda" {
Expand Down