Skip to content

Commit 461b4c6

Browse files
committed
doc: update readme with cdk-lib changes
1 parent 0496d17 commit 461b4c6

File tree

6 files changed

+61
-18
lines changed

6 files changed

+61
-18
lines changed

.github/workflows/build.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v4
10-
- uses: actions/setup-node@v3
10+
- uses: actions/setup-node@v4
1111
with:
1212
node-version: "20"
13+
- name: Install latest CDK CLI
14+
run: |
15+
npm install -g aws-cdk@latest
16+
cdk --version
1317
- name: Formatting
1418
run: |
1519
npm ci
@@ -23,7 +27,7 @@ jobs:
2327
npm audit
2428
npm run build
2529
npm run test
26-
npx cdk synth
30+
cdk synth
2731
- name: PyTests
2832
# Suppression of pip audit failure until langchain is upgraded.
2933
run: |

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ This blueprint deploys the complete AWS GenAI LLM Chatbot solution in your AWS a
2727
- AWS CLI configured with credentials
2828
- Node.js 18+ and npm
2929
- Python 3.8+
30+
- AWS CDK CLI version compatible with aws-cdk-lib 2.206.0 or later
31+
```bash
32+
# Install or update the CDK CLI globally
33+
npm install -g aws-cdk@latest
34+
35+
# Verify the installed version
36+
cdk --version
37+
```
38+
39+
> **Important**: The CDK CLI version must be compatible with the aws-cdk-lib version used in this project (currently 2.206.0). If you encounter a "Cloud assembly schema version mismatch" error during deployment, update your CDK CLI to the latest version using the command above.
3040
3141
### Deployment
3242

lib/authentication/lambda/addFederatedUserToUserGroup/index.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def add_user_to_group(cognito, username, group_name, user_pool_id):
7272

7373
def handler(event, context):
7474
print(f"Event received: {event}")
75-
75+
7676
# Handle different trigger types with different event structures
7777
if "request" in event and "userAttributes" in event["request"]:
7878
# POST_AUTHENTICATION trigger
@@ -88,18 +88,30 @@ def handler(event, context):
8888
new_group = user_attributes.get("custom:chatbot_role")
8989
user_pool_id = event["userPoolId"]
9090
trigger_type = "PRE_AUTHENTICATION"
91-
elif "request" in event and "userAttributes" in event["request"] and "validationData" in event["request"]:
91+
elif (
92+
"request" in event
93+
and "userAttributes" in event["request"]
94+
and "validationData" in event["request"]
95+
):
9296
# POST_CONFIRMATION trigger
9397
user_attributes = event["request"]["userAttributes"]
9498
username = user_attributes.get("sub") or user_attributes.get("username")
9599
new_group = user_attributes.get("custom:chatbot_role")
96100
user_pool_id = event["userPoolId"]
97101
trigger_type = "POST_CONFIRMATION"
98-
elif "request" in event and "userAttributes" in event["request"] and "validationData" not in event["request"]:
102+
elif (
103+
"request" in event
104+
and "userAttributes" in event["request"]
105+
and "validationData" not in event["request"]
106+
):
99107
# PRE_SIGN_UP trigger
100108
user_attributes = event["request"]["userAttributes"]
101109
# For Pre sign-up, username might be in different fields
102-
username = user_attributes.get("sub") or user_attributes.get("username") or user_attributes.get("email")
110+
username = (
111+
user_attributes.get("sub")
112+
or user_attributes.get("username")
113+
or user_attributes.get("email")
114+
)
103115
new_group = user_attributes.get("custom:chatbot_role")
104116
user_pool_id = event["userPoolId"]
105117
trigger_type = "PRE_SIGN_UP"
@@ -115,7 +127,7 @@ def handler(event, context):
115127

116128
# Get default group from environment variable or use 'user' as fallback
117129
default_group = os.environ.get("DEFAULT_USER_GROUP", "user")
118-
130+
119131
# If no custom:chatbot_role is provided, use default group
120132
if not new_group:
121133
new_group = default_group
@@ -125,18 +137,22 @@ def handler(event, context):
125137
if trigger_type == "PRE_SIGN_UP":
126138
print("Pre sign-up trigger - user will be created after this trigger completes")
127139
print(f"Will assign user to group: {new_group}")
128-
print("Note: Group assignment will happen in a separate trigger (POST_CONFIRMATION)")
129-
140+
print(
141+
"Note: Group assignment will happen in a separate \
142+
trigger (POST_CONFIRMATION)"
143+
)
144+
130145
# For Pre sign-up, we can only validate or modify the sign-up request
131146
# We cannot assign groups yet as the user doesn't exist
132-
# The group assignment will need to happen in POST_CONFIRMATION or PRE_AUTHENTICATION
133-
147+
# The group assignment will need to happen in
148+
# POST_CONFIRMATION or PRE_AUTHENTICATION
149+
134150
# You might want to add the group information to the user attributes
135151
# so it can be used later in POST_CONFIRMATION
136152
if "custom:chatbot_role" not in user_attributes:
137153
user_attributes["custom:chatbot_role"] = new_group
138154
print(f"Added custom:chatbot_role attribute: {new_group}")
139-
155+
140156
return event
141157

142158
# For other triggers (PRE_AUTHENTICATION, POST_AUTHENTICATION, POST_CONFIRMATION)

package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"@types/node": "20.1.7",
6565
"@typescript-eslint/eslint-plugin": "^6.0.0",
6666
"@typescript-eslint/parser": "^6.0.0",
67-
"aws-cdk": "~2.1010.0",
67+
"aws-cdk": "^2.211.0",
6868
"aws-xray-sdk-core": "3.10.1",
6969
"eslint": "^8.45.0",
7070
"eslint-config-prettier": "^9.1.0",
@@ -85,7 +85,7 @@
8585
"@aws-cdk/aws-apigatewayv2-integrations-alpha": "^2.114.1-alpha.0",
8686
"@aws-cdk/aws-cognito-identitypool-alpha": "^2.114.1-alpha.0",
8787
"@cdklabs/generative-ai-cdk-constructs": "^0.1.122",
88-
"aws-cdk-lib": "~2.206.0",
88+
"aws-cdk-lib": "^2.211.0",
8989
"cdk-monitoring-constructs": "8.1.0",
9090
"cdk-nag": "2.28.139",
9191
"commander": "^11.0.0",

tests/authentication/lambda/addFederatedUserToGroup_test.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,19 @@ def test_handler_no_chatbot_role(mock_cognito):
141141
"userPoolId": "us-east-1_testpool",
142142
}
143143

144+
# Mock the response to prevent infinite pagination
145+
mock_cognito.admin_list_groups_for_user.return_value = {
146+
"Groups": [] # User has no current groups
147+
}
148+
144149
result = handler(event, None)
145150

146151
assert result == event
147-
mock_cognito.admin_list_groups_for_user.assert_not_called()
152+
# Should call admin_list_groups_for_user once to check current groups
153+
mock_cognito.admin_list_groups_for_user.assert_called_once()
154+
# Should add user to default group since they have no custom:chatbot_role
155+
mock_cognito.admin_add_user_to_group.assert_called_once_with(
156+
UserPoolId="us-east-1_testpool",
157+
Username="test-user-123",
158+
GroupName="user", # default group
159+
)

0 commit comments

Comments
 (0)