Skip to content

Commit a00511b

Browse files
author
Adetokunbo Ige
committed
chore: update policy
Signed-off-by: Adetokunbo Ige <[email protected]>
1 parent 64cd080 commit a00511b

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

todo-app/__main__.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,30 @@
3434
policy_arn="arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
3535
)
3636

37-
# Define an IAM policy that allows DynamoDB scan action
38-
dynamodb_scan_policy = aws.iam.Policy("dynamodb-policy",
39-
policy={
37+
# Define IAM policy for DynamoDB access
38+
dynamodb_policy = aws.iam.Policy(
39+
"dynamodb-policy",
40+
description="Policy for DynamoDB access",
41+
policy=pulumi.Output.json_dumps({
4042
"Version": "2012-10-17",
4143
"Statement": [
4244
{
4345
"Effect": "Allow",
44-
"Action": "dynamodb:Scan",
45-
"Resource": "arn:aws:dynamodb:us-east-1:289940214902:table/todo-dev-*"
46+
"Action": [
47+
"dynamodb:Scan",
48+
"dynamodb:PutItem",
49+
"dynamodb:GetItem",
50+
"dynamodb:UpdateItem",
51+
"dynamodb:DeleteItem",
52+
"dynamodb:Query"
53+
],
54+
"Resource": [
55+
pulumi.Output.format("{}",dynamodb_table.arn),
56+
pulumi.Output.format("{}/*",dynamodb_table.arn) # Include index access
57+
]
4658
}
4759
]
48-
}
60+
})
4961
)
5062

5163
# Attach the policy to the Lambda execution role
@@ -55,22 +67,25 @@
5567
)
5668

5769
# Define a DynamoDB table
58-
dynamodb_table = aws.dynamodb.Table(f"todo-{environment}",
59-
hash_key="id", # Partition key
60-
range_key="timestamp", # Sort key
70+
# Define DynamoDB Table
71+
dynamodb_table = aws.dynamodb.Table(
72+
f"todo-{environment}",
73+
name=f"todo-{environment}", # Explicit table name
74+
hash_key="id",
75+
range_key="timestamp",
6176
attributes=[
6277
aws.dynamodb.TableAttributeArgs(
6378
name="id",
64-
type="S" # S for string
79+
type="S"
6580
),
6681
aws.dynamodb.TableAttributeArgs(
6782
name="timestamp",
68-
type="N" # N for number
83+
type="N"
6984
),
7085
],
71-
billing_mode="PAY_PER_REQUEST", # Use on-demand mode (no provisioned throughput)
86+
billing_mode="PAY_PER_REQUEST",
7287
tags={
73-
"Environment": "dev",
88+
"Environment": environment,
7489
"Created_By": "Pulumi"
7590
}
7691
)

0 commit comments

Comments
 (0)