Skip to content

Commit 1736d42

Browse files
committed
fix ast error; fix deployment to multi-region bug
1 parent 0867807 commit 1736d42

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

aws_sra_examples/solutions/genai/bedrock_org/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ aws cloudformation create-stack \
8585
ParameterKey=pBedrockOrgLambdaRoleName,ParameterValue=sra-bedrock-org-lambda-role \
8686
ParameterKey=pBedrockAccounts,ParameterValue='["123456789012","234567890123"]' \
8787
ParameterKey=pBedrockRegions,ParameterValue='["us-east-1","us-west-2"]' \
88-
ParameterKey=pBedrockModelEvalBucketRuleParams,ParameterValue='{"deploy": "true", "accounts": ["123456789012"], "regions": ["us-east-1"], "input_params": {"BucketName": "evaluation-bucket"}}' \
88+
ParameterKey=pBedrockModelEvalBucketRuleParams,ParameterValue='{"deploy": "true", "accounts": ["123456789012"], "regions": ["us-east-1"], "input_params": {"BucketNamePrefix": "evaluation-bucket","CheckRetention": "true", "CheckEncryption": "true", "CheckLogging": "true", "CheckObjectLocking": "true", "CheckVersioning": "true"}}' \
8989
ParameterKey=pBedrockIAMUserAccessRuleParams,ParameterValue='{"deploy": "true", "accounts": ["123456789012"], "regions": ["us-east-1"], "input_params": {}}' \
9090
ParameterKey=pBedrockGuardrailsRuleParams,ParameterValue='{"deploy": "true", "accounts": ["123456789012"], "regions": ["us-east-1"], "input_params": {"content_filters": "true", "denied_topics": "true", "word_filters": "true", "sensitive_info_filters": "true", "contextual_grounding": "true"}}' \
9191
ParameterKey=pBedrockVPCEndpointsRuleParams,ParameterValue='{"deploy": "true", "accounts": ["123456789012"], "regions": ["us-east-1"], "input_params": {"check_bedrock": "true", "check_bedrock_agent": "true", "check_bedrock_agent_runtime": "true", "check_bedrock_runtime": "true"}}' \
@@ -109,6 +109,7 @@ aws cloudformation create-stack \
109109
- Always validate the JSON parameters for correctness to avoid deployment errors.
110110
- Ensure the --capabilities CAPABILITY_NAMED_IAM flag is included to allow CloudFormation to create the necessary IAM resources.
111111
- An example test fork URL for `pSRARepoZipUrl` is - `https://github.com/liamschn/aws-security-reference-architecture-examples/archive/refs/heads/sra-genai.zip`
112+
- The eval job bucket config rule will append `-<ACCOUNTID>-<REGION>` to the `BucketNamePrefix` parameter provided to get the existing bucket name(s). Ensure any S3 eval job bucket names to be checked match this naming convention.
112113

113114

114115
2. Monitor the stack creation progress in the AWS CloudFormation Console or via CLI commands.
@@ -132,14 +133,20 @@ Once the stack is deployed, the Bedrock Lambda function (`sra-bedrock-org`) will
132133
This section explains the parameters in the CloudFormation template that require JSON string values. Each parameter's structure and purpose are described in detail to assist in their configuration.
133134

134135
### `pBedrockModelEvalBucketRuleParams`
135-
- **Purpose**: Configures a rule to validate a Bedrock Model Evaluation bucket.
136+
- **Purpose**: Configures a rule to validate a Bedrock Model Evaluation bucket. NOTE: `-<ACCOUNTID>-<REGION>` will be appended to get the existing bucket name(s). Ensure any S3 eval job bucket names to be checked match this naming convention.
136137
- **Structure**:
137138
{
138139
"deploy": "true|false",
139140
"accounts": ["account_id1", "account_id2"],
140141
"regions": ["region1", "region2"],
141142
"input_params": {
142-
"BucketName": "bucket-name"
143+
"BucketNamePrefix": "bucket-name"
144+
"CheckRetention": "true|false",
145+
"CheckEncryption": "true|false",
146+
"CheckLogging": "true|false",
147+
"CheckObjectLocking": "true|false",
148+
"CheckVersioning": "true|false",
149+
143150
}
144151
}
145152
- **Fields**:

aws_sra_examples/solutions/genai/bedrock_org/lambda/rules/sra_bedrock_check_eval_job_bucket/app.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
SERVICE_NAME = "bedrock.amazonaws.com"
3232
BUCKET_NAME = ""
3333

34-
3534
def evaluate_compliance(event: dict, context: Any) -> tuple[str, str]: # noqa: U100, CCR001, C901
3635
"""Evaluate the S3 bucket for the compliance.
3736
@@ -47,15 +46,16 @@ def evaluate_compliance(event: dict, context: Any) -> tuple[str, str]: # noqa:
4746
# Initialize AWS clients
4847
s3 = boto3.client("s3")
4948
sts = boto3.client("sts")
49+
session = boto3.Session()
50+
region = session.region_name
5051
account = sts.get_caller_identity().get("Account")
5152
# Get rule parameters
5253
params = ast.literal_eval(event["ruleParameters"])
5354
LOGGER.info(f"Parameters: {params}")
5455
LOGGER.info(f"Account: {account}")
55-
buckets = params.get("Buckets", {account: ""})
56-
LOGGER.info(f"Buckets: {buckets}")
57-
buckets = ast.literal_eval(buckets)
58-
bucket_name = buckets.get(account, "")
56+
bucket_prefix = params.get("BucketNamePrefix", "")
57+
LOGGER.info(f"Bucket Prefix: {bucket_prefix}")
58+
bucket_name = bucket_prefix + "-" + account + "-" + region
5959
LOGGER.info(f"Bucket Name: {bucket_name}")
6060
BUCKET_NAME = bucket_name
6161

aws_sra_examples/solutions/genai/bedrock_org/templates/sra-bedrock-org-main.yaml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,24 @@ Parameters:
9696

9797
pBedrockModelEvalBucketRuleParams:
9898
Type: String
99-
Default: '{"deploy": "true", "accounts": ["444455556666"], "regions": ["us-west-2"], "input_params": {"Buckets": {"444455556666": "model-invocation-log-bucket-444455556666"},"CheckRetention": "true", "CheckEncryption": "true", "CheckLogging": "true", "CheckObjectLocking": "true", "CheckVersioning": "true"}}'
99+
Default: '{"deploy": "true", "accounts": ["444455556666"], "regions": ["us-west-2"], "input_params": {"BucketNamePrefix": "model-invocation-log-bucket","CheckRetention": "true", "CheckEncryption": "true", "CheckLogging": "true", "CheckObjectLocking": "true", "CheckVersioning": "true"}}'
100100
Description: Bedrock Model Evaluation Job Config Rule Parameters
101-
AllowedPattern: ^\{"deploy"\s*:\s*"(true|false)",\s*"accounts"\s*:\s*\[((?:"[0-9]+"(?:\s*,\s*)?)*)\],\s*"regions"\s*:\s*\[((?:"[a-z0-9-]+"(?:\s*,\s*)?)*)\],\s*"input_params"\s*:\s*(\{\s*(?:"Buckets"\s*:\s*\{(\s*"[0-9]+"\s*:\s*"[a-zA-Z0-9-]*"\s*,?\s*)*\},\s*"CheckRetention"\s*:\s*"(true|false)",\s*"CheckEncryption"\s*:\s*"(true|false)",\s*"CheckLogging"\s*:\s*"(true|false)",\s*"CheckObjectLocking"\s*:\s*"(true|false)",\s*"CheckVersioning"\s*:\s*"(true|false)"\s*)}})$
101+
AllowedPattern: ^\{"deploy"\s*:\s*"(true|false)",\s*"accounts"\s*:\s*\[((?:"[0-9]+"(?:\s*,\s*)?)*)\],\s*"regions"\s*:\s*\[((?:"[a-z0-9-]+"(?:\s*,\s*)?)*)\],\s*"input_params"\s*:\s*(\{\s*(?:"BucketNamePrefix"\s*:\s*(\s*"[a-zA-Z0-9-]+"\s*),\s*"CheckRetention"\s*:\s*"(true|false)",\s*"CheckEncryption"\s*:\s*"(true|false)",\s*"CheckLogging"\s*:\s*"(true|false)",\s*"CheckObjectLocking"\s*:\s*"(true|false)",\s*"CheckVersioning"\s*:\s*"(true|false)"\s*)}})$
102102
ConstraintDescription:
103-
"Must be a valid JSON string containing: 'deploy' (true/false), 'accounts' (array of account numbers),
104-
'regions' (array of region names), and 'input_params' object/dict. Arrays can be empty.
105-
Example: {\"deploy\": \"true\", \"accounts\": [\"123456789012\"], \"regions\": [\"us-east-1\"], \"input_params\": {\"Buckets\": {\"123456789012\": \"model-invocation-log-bucket-123456789012\"}, \"CheckRetention\": \"true\", \"CheckEncryption\": \"true\", \"CheckLogging\": \"true\", \"CheckObjectLocking\": \"true\", \"CheckVersioning\": \"true\"}} or
106-
{\"deploy\": \"false\", \"accounts\": [], \"regions\": [], \"input_params\": {\"Buckets\": {}, \"CheckRetention\": \"true\", \"CheckEncryption\": \"true\", \"CheckLogging\": \"true\", \"CheckObjectLocking\": \"true\", \"CheckVersioning\": \"true\"}}"
103+
"The parameter value must be a valid JSON object with the following structure:
104+
{
105+
'deploy': 'true' or 'false',
106+
'accounts': an array of numeric AWS account IDs,
107+
'regions': an array of valid AWS region identifiers,
108+
'input_params': {
109+
'BucketNamePrefix': a valid bucket name prefix,
110+
'CheckRetention': 'true' or 'false',
111+
'CheckEncryption': 'true' or 'false',
112+
'CheckLogging': 'true' or 'false',
113+
'CheckObjectLocking': 'true' or 'false',
114+
'CheckVersioning': 'true' or 'false'
115+
}
116+
}. Ensure all keys and values conform to the specified types and format."
107117

108118
pBedrockIAMUserAccessRuleParams:
109119
Type: String

0 commit comments

Comments
 (0)