Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bedrock batch inference #6524

Merged
merged 12 commits into from
Jan 15, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,73 @@ resource "aws_iam_policy" "textract_integration" {
description = "Permissions needed to allow access to Textract from tooling."
policy = data.aws_iam_policy_document.textract_integration.json
}

##################################################
# Bedrock Batch Inference
##################################################

data "aws_iam_policy_document" "bedrock_batch_inference" {
statement {
sid = "AllowBedrockAssumeRoleForBatchInference"
actions = ["sts:AssumeRole"]
condition {
test = "StringEquals"
variable = "aws:SourceAccount"
values = [data.aws_caller_identity.current.account_id]
}
condition {
test = "ArnLike"
variable = "aws:SourceArn"
values = ["arn:aws:bedrock:*:${data.aws_caller_identity.current.account_id}:model-invocation-job/*"]
}
effect = "Allow"
principals {
type = "Service"
identifiers = ["bedrock.amazonaws.com"]
}
}
}

resource "aws_iam_role" "bedrock_batch_inference" {
name = "bedrock-batch-inference-role"
description = "IAM role for AWS Bedrock to perform batch inference tasks as part of model invocation workflows."
assume_role_policy = data.aws_iam_policy_document.bedrock_batch_inference.json
}

resource "aws_iam_role_policy_attachment" "bedrock_batch_inference" {
role = aws_iam_role.bedrock_batch_inference.name
policy_arn = aws_iam_policy.bedrock_integration.arn
}

# Bedrock Batch Inference s3 access
data "aws_iam_policy_document" "bedrock_batch_inference_s3_access" {
statement {
sid = "bedrock-batch-inference-s3-access"
effect = "Allow"

actions = [
"s3:GetObject",
"s3:PutObject",
"s3:ListBucket",
]

resources = [
"arn:aws:s3:::*"
]

condition {
test = "StringEquals"
variable = "aws:ResourceAccount"
values = [
data.aws_caller_identity.current.account_id
]
}
}
}

resource "aws_iam_policy" "bedrock_batch_inference_s3_access" {
name = "bedrock-batch-inference-s3-access"
description = "S3 access policy for Bedrock batch inference."
policy = data.aws_iam_policy_document.bedrock_batch_inference_s3_access.json
}

Loading