Skip to content

Commit 648d7f1

Browse files
committed
updated IAM
1 parent 82172d0 commit 648d7f1

4 files changed

Lines changed: 81 additions & 83 deletions

File tree

s3-lambda-agentcore/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
metadata
2+
invoke_agent.zip

s3-lambda-agentcore/deploy.tf

Lines changed: 78 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ data "aws_iam_policy_document" "agentcore_permissions_policy" {
4747
effect = "Allow"
4848
resources = [aws_ecr_repository.agentcore_repo.arn]
4949
}
50-
statement {
51-
actions = [
52-
"logs:CreateLogGroup",
53-
"logs:CreateLogStream",
54-
"logs:PutLogEvents",
55-
]
56-
effect = "Allow"
57-
resources = [
58-
"arn:aws:logs:${local.region}:${local.account_id}:log-group:/aws/bedrock-agentcore/*",
59-
"arn:aws:logs:${local.region}:${local.account_id}:log-group:/aws/bedrock-agentcore/*:log-stream:*"
60-
]
61-
}
50+
statement {
51+
actions = [
52+
"logs:CreateLogGroup",
53+
"logs:CreateLogStream",
54+
"logs:PutLogEvents",
55+
]
56+
effect = "Allow"
57+
resources = [
58+
"arn:aws:logs:${local.region}:${local.account_id}:log-group:/aws/bedrock-agentcore/*",
59+
"arn:aws:logs:${local.region}:${local.account_id}:log-group:/aws/bedrock-agentcore/*:log-stream:*"
60+
]
61+
}
6262
statement {
6363
actions = [
6464
"xray:PutTraceSegments",
@@ -67,33 +67,36 @@ statement {
6767
effect = "Allow"
6868
resources = ["*"]
6969
}
70-
statement {
71-
actions = [
72-
"bedrock:InvokeModel",
73-
"bedrock:InvokeModelWithResponseStream"
74-
]
75-
effect = "Allow"
76-
resources = [
77-
"arn:aws:bedrock:${local.region}::foundation-model/amazon.nova-pro-v1"
78-
]
79-
}
8070
statement {
81-
actions = [
82-
"s3:GetObject"
83-
]
84-
effect = "Allow"
85-
resources = [
86-
"${aws_s3_bucket.input_bucket.arn}/*"
87-
]
88-
}
89-
statement {
90-
actions = [
91-
"s3:ListBucket"
92-
]
93-
effect = "Allow"
94-
resources = [
95-
aws_s3_bucket.input_bucket.arn
96-
]
71+
actions = [
72+
"bedrock:InvokeModel",
73+
"bedrock:InvokeModelWithResponseStream"
74+
]
75+
effect = "Allow"
76+
resources = [
77+
"arn:aws:bedrock:*::foundation-model/amazon.nova-pro-v1",
78+
"arn:aws:bedrock:*::foundation-model/amazon.nova-pro-v1:0",
79+
"arn:aws:bedrock:${local.region}:${local.account_id}:inference-profile/*"
80+
]
81+
}
82+
statement {
83+
actions = [
84+
"s3:GetObject"
85+
]
86+
effect = "Allow"
87+
resources = [
88+
"${aws_s3_bucket.input_bucket.arn}/*"
89+
]
90+
}
91+
statement {
92+
actions = [
93+
"s3:ListBucket"
94+
]
95+
effect = "Allow"
96+
resources = [
97+
aws_s3_bucket.input_bucket.arn
98+
]
99+
}
97100
}
98101

99102
resource "aws_iam_role" "agentcore_role" {
@@ -187,47 +190,45 @@ data "aws_iam_policy_document" "lambda_assume_role_policy" {
187190

188191
data "aws_iam_policy_document" "lambda_permissions_policy" {
189192
statement {
190-
actions = ["ecr:GetAuthorizationToken"]
193+
actions = [
194+
"logs:CreateLogGroup",
195+
"logs:CreateLogStream",
196+
"logs:PutLogEvents"
197+
]
191198
effect = "Allow"
192-
resources = ["*"]
199+
resources = [
200+
"arn:aws:logs:${local.region}:${local.account_id}:log-group:/aws/lambda/${aws_lambda_function.s3_agent_lambda_function.function_name}:*"
201+
]
193202
}
194-
statement {
195-
actions = [
196-
"logs:CreateLogGroup",
197-
"logs:CreateLogStream",
198-
"logs:PutLogEvents"
199-
]
200-
effect = "Allow"
201-
resources = [
202-
"arn:aws:logs:${local.region}:${local.account_id}:log-group:/aws/lambda/${aws_lambda_function.s3_agent_lambda_function.function_name}:*"
203-
]
204-
}
205-
statement {
206-
actions = [
207-
"s3:GetObject"
208-
]
209-
effect = "Allow"
210-
resources = [
211-
"${aws_s3_bucket.input_bucket.arn}/*"
212-
]
213-
}
214-
statement {
215-
actions = [
216-
"s3:PutObject"
217-
]
218-
effect = "Allow"
219-
resources = [
220-
"${aws_s3_bucket.output_bucket.arn}/*"
221-
]
222-
}
223-
statement {
224-
actions = [
225-
"bedrock-agentcore:InvokeAgentRuntime"
226-
]
227-
effect = "Allow"
228-
resources = [
229-
aws_bedrockagentcore_agent_runtime.agentcore_runtime.agent_runtime_arn
230-
]
203+
statement {
204+
actions = [
205+
"s3:GetObject"
206+
]
207+
effect = "Allow"
208+
resources = [
209+
"${aws_s3_bucket.input_bucket.arn}/*"
210+
]
211+
}
212+
statement {
213+
actions = [
214+
"s3:PutObject"
215+
]
216+
effect = "Allow"
217+
resources = [
218+
"${aws_s3_bucket.output_bucket.arn}/*"
219+
]
220+
}
221+
statement {
222+
actions = [
223+
"bedrock-agentcore:InvokeAgentRuntime"
224+
]
225+
effect = "Allow"
226+
resources = [
227+
aws_bedrockagentcore_agent_runtime.agentcore_runtime.agent_runtime_arn,
228+
"${aws_bedrockagentcore_agent_runtime.agentcore_runtime.agent_runtime_arn}/*"
229+
]
230+
}
231+
depends_on = [aws_bedrockagentcore_agent_runtime.agentcore_runtime]
231232
}
232233

233234
resource "aws_iam_role" "lambda_role" {

s3-lambda-agentcore/lambda/invoke_agent.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,4 @@ def lambda_handler(event,context):
101101
'input': f"s3://{bucket}/{object_key}",
102102
'output': f"s3://{output_bucket}/{output_key}"
103103
})
104-
}
105-
106-
107-
# This code is provided on best effort basis.
108-
# Kindly note this code is not tested on edge cases these may create issues if you deploy it over production environment.
109-
# Use this code for referene purpose only.
104+
}
-1.34 KB
Binary file not shown.

0 commit comments

Comments
 (0)