Skip to content

Commit 3644ae7

Browse files
committed
patch: Add S3 permissions to Lambda
1 parent dafeb16 commit 3644ae7

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,9 @@ def handler(event, context) -> str: # type: ignore[no-untyped-def]
568568

569569
logger.log_info("Initialised logging.")
570570

571+
# Log the configuration parameters
572+
logger.log_info(config)
573+
571574
# Get the environment variables
572575

573576
org, app_client_id, aws_default_region, aws_secret_name = get_environment_variables()

terraform/service/data.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ data "aws_iam_policy_document" "lambda_logging" {
4343
}
4444
}
4545

46+
data "aws_iam_policy_document" "lambda_s3_policy" {
47+
statement {
48+
effect = "Allow"
49+
50+
actions = [
51+
"s3:ListAllMyBuckets", # Allows listing all buckets in the account
52+
"s3:GetObject", # Allows reading objects in buckets
53+
"s3:ListBucket"
54+
]
55+
56+
resources = [
57+
"arn:aws:s3:::*", # Allows access to all buckets
58+
"arn:aws:s3:::*/*" # Allows access to all objects within all buckets
59+
]
60+
}
61+
}
62+
4663
data "aws_iam_policy_document" "lambda_secret_manager_policy" {
4764
statement {
4865
effect = "Allow"

terraform/service/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ resource "aws_iam_role_policy_attachment" "lambda_logs" {
9999
policy_arn = aws_iam_policy.lambda_logging.arn
100100
}
101101

102+
resource "aws_iam_policy" "lambda_s3_policy" {
103+
name = "${var.lambda_name}-${var.env_name}-s3-policy"
104+
description = "IAM policy for S3 access for Lambda function"
105+
policy = data.aws_iam_policy_document.lambda_s3_policy.json
106+
}
107+
108+
resource "aws_iam_role_policy_attachment" "s3_policy" {
109+
role = aws_iam_role.lambda_function_role.name
110+
policy_arn = aws_iam_policy.lambda_s3_policy.arn
111+
}
112+
102113
resource "aws_iam_policy" "lambda_secret_manager_policy" {
103114
name = "${var.lambda_name}-${var.env_name}-secret-manager-policy"
104115
description = "IAM policy for Secret Manager access for Lambda function"

0 commit comments

Comments
 (0)