From db781a1821e16003a78cdbb85df3253697c59d31 Mon Sep 17 00:00:00 2001
From: "abir.chebbi" <abir.chebbi@hes-so.ch>
Date: Fri, 11 Apr 2025 16:28:49 +0200
Subject: [PATCH] add account_id as an argument

---
 Part1/create-vector-db.py | 11 ++++++-----
 README.md                 |  1 +
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/Part1/create-vector-db.py b/Part1/create-vector-db.py
index 489d74e..b92bf31 100644
--- a/Part1/create-vector-db.py
+++ b/Part1/create-vector-db.py
@@ -76,7 +76,7 @@ def createNetworkPolicy(client,policy_name,collection_name):
             raise error
 
 
-def createAccessPolicy(client, policy_name, collection_name, IAM_USER):
+def createAccessPolicy(client, policy_name, collection_name, IAM_USER,ACCOUNT_ID):
     """Creates a data access policy for the specified collection."""
     try:
         policy_content = f"""
@@ -106,7 +106,7 @@ def createAccessPolicy(client, policy_name, collection_name, IAM_USER):
                         "ResourceType": "index"
                     }}
                 ],
-                "Principal": ["arn:aws:iam::768034348959:user/{IAM_USER}"]
+                "Principal": ["arn:aws:iam::{ACCOUNT_ID}:user/{IAM_USER}"]
             }}
         ]
         """
@@ -140,13 +140,13 @@ def waitForCollectionCreation(client,collection_name):
     return final_host
 
 
-def main(collection_name,IAM_USER):
+def main(collection_name,IAM_USER,ACCOUNT_ID):
     encryption_policy_name = f'{collection_name}-encryption-policy'
     network_policy_name = f'{collection_name}-network-policy'
     access_policy_name = f'{collection_name}-access-policy'
     createEncryptionPolicy(client, encryption_policy_name, collection_name)
     createNetworkPolicy(client, network_policy_name, collection_name)
-    createAccessPolicy(client, access_policy_name, collection_name,IAM_USER)
+    createAccessPolicy(client, access_policy_name, collection_name,IAM_USER,ACCOUNT_ID)
     collection = client.create_collection(name=collection_name,type='VECTORSEARCH')
     ENDPOINT= waitForCollectionCreation(client,collection_name)
 
@@ -157,5 +157,6 @@ if __name__== "__main__":
     parser = argparse.ArgumentParser(description="Create collection")
     parser.add_argument("--collection_name", help="The name of the collection")
     parser.add_argument("--iam_user", help="The iam user")
+    parser.add_argument("--account_id", help="The account id")
     args = parser.parse_args()
-    main(args.collection_name,args.iam_user)
+    main(args.collection_name,args.iam_user,args.account_id)
diff --git a/README.md b/README.md
index 7b7fb46..a3bc2a0 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,7 @@ Where:
 - **[Name_of_colletion]**: Name of the collection that you want to create.
 - **[YourIAM_user]** : the IAM user is `CloudSys-group-XX`, with "XX" representing your group number.
 
+
 This script performs the following actions:
 
 * Sets up encryption, network, and data access policies for the collection.
-- 
GitLab