Skip to content

Commit 559d465

Browse files
committed
2 parents c008556 + 9d31f9d commit 559d465

File tree

11 files changed

+34
-29
lines changed

11 files changed

+34
-29
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src.zip

apigw-lambda-dynamodb-terraform/main.tf

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
aws = {
44
source = "hashicorp/aws"
5-
version = "~> 4.0.0"
5+
version = "~> 5.0"
66
}
77
random = {
88
source = "hashicorp/random"
@@ -56,9 +56,13 @@ resource "aws_s3_bucket" "lambda_bucket" {
5656
force_destroy = true
5757
}
5858

59-
resource "aws_s3_bucket_acl" "private_bucket" {
59+
resource "aws_s3_bucket_public_access_block" "private_bucket" {
6060
bucket = aws_s3_bucket.lambda_bucket.id
61-
acl = "private"
61+
62+
block_public_acls = true
63+
block_public_policy = true
64+
ignore_public_acls = true
65+
restrict_public_buckets = true
6266
}
6367

6468
data "archive_file" "lambda_zip" {
@@ -85,7 +89,7 @@ resource "aws_lambda_function" "apigw_lambda_ddb" {
8589
s3_bucket = aws_s3_bucket.lambda_bucket.id
8690
s3_key = aws_s3_object.this.key
8791

88-
runtime = "python3.8"
92+
runtime = "python3.13"
8993
handler = "app.lambda_handler"
9094

9195
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
@@ -222,4 +226,4 @@ resource "aws_lambda_permission" "api_gw" {
222226
principal = "apigateway.amazonaws.com"
223227

224228
source_arn = "${aws_apigatewayv2_api.http_lambda.execution_arn}/*/*"
225-
}
229+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lambda.zip

dynamodb-streams-lambda-terraform/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ After deployment, add an item to the DynamoDB table. Go to the CloudWatch Logs f
6161
```bash
6262
terraform show
6363
```
64-
```
64+
6565
----
6666
Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
6767

dynamodb-streams-lambda-terraform/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
aws = {
44
source = "hashicorp/aws"
5-
version = "~> 3.27"
5+
version = "~> 5.0"
66
}
77
}
88

@@ -40,7 +40,7 @@ resource "aws_lambda_function" "lambda_dynamodb_stream_handler" {
4040
source_code_hash = data.archive_file.lambda_zip_file.output_base64sha256
4141
handler = "index.handler"
4242
role = aws_iam_role.iam_for_lambda.arn
43-
runtime = "nodejs16.x"
43+
runtime = "nodejs22.x"
4444
}
4545

4646
data "archive_file" "lambda_zip_file" {
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lambda.zip

eventbridge-sns-lambda-terraform/main.tf

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
required_providers {
77
aws = {
88
source = "hashicorp/aws"
9-
version = "~> 3.27"
9+
version = "~> 5.0"
1010
}
1111
}
1212

@@ -103,15 +103,11 @@ resource "aws_lambda_function" "lambda_function" {
103103
source_code_hash = data.archive_file.lambda_zip_file.output_base64sha256
104104
handler = "app.handler"
105105
role = aws_iam_role.lambda_iam_role.arn
106-
runtime = "nodejs16.x"
106+
runtime = "nodejs22.x"
107107
}
108108

109-
110109
resource "aws_iam_role" "lambda_iam_role" {
111-
name_prefix = "LambdaSNSRole-"
112-
managed_policy_arns = [
113-
data.aws_iam_policy.lambda_basic_execution_role_policy.arn
114-
]
110+
name_prefix = "LambdaSNSRole-"
115111

116112
assume_role_policy = <<EOF
117113
{
@@ -130,6 +126,11 @@ resource "aws_iam_role" "lambda_iam_role" {
130126
EOF
131127
}
132128

129+
resource "aws_iam_role_policy_attachment" "lambda_basic_execution" {
130+
role = aws_iam_role.lambda_iam_role.name
131+
policy_arn = data.aws_iam_policy.lambda_basic_execution_role_policy.arn
132+
}
133+
133134
resource "aws_lambda_permission" "with_sns" {
134135
statement_id = "AllowExecutionFromSNS"
135136
action = "lambda:InvokeFunction"
@@ -138,10 +139,6 @@ resource "aws_lambda_permission" "with_sns" {
138139
source_arn = aws_sns_topic.MySNSTopic.arn
139140
}
140141

141-
142-
143-
144-
145142
//---------------------------------------------------------
146143
// Output
147144
//---------------------------------------------------------
@@ -160,4 +157,4 @@ output "SNS-Topic-ARN" {
160157
output "Lambda-function" {
161158
value = aws_lambda_function.lambda_function.arn
162159
description = "TopicSubscriberFunction function name"
163-
}
160+
}

eventbridge-sns-lambda-terraform/src/app.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
* SPDX-License-Identifier: MIT-0
33
*/
44

5-
const AWS = require('aws-sdk')
6-
AWS.config.region = process.env.AWS_REGION
7-
const sns = new AWS.SNS({apiVersion: '2012-11-05'})
8-
95
// The Lambda handler
106
exports.handler = async (event) => {
117
console.log("Hello World !")
12-
}
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lambda.zip

0 commit comments

Comments
 (0)