qyle commited on
Commit
0ef1f88
·
verified ·
1 Parent(s): e82f783

environmental table dev

Browse files
Files changed (1) hide show
  1. helpers/dynamodb_helper.py +7 -5
helpers/dynamodb_helper.py CHANGED
@@ -19,7 +19,9 @@ AWS_ACCESS_KEY = os.getenv("AWS_ACCESS_KEY", None)
19
  AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY", None)
20
  DYNAMODB_ENDPOINT = os.getenv("DYNAMODB_ENDPOINT", None)
21
  DDB_TABLE = os.getenv("DDB_TABLE", "chatbot-conversations")
22
- ENVIRONMENT_IMPACT_TABLE = "environmental-impact"
 
 
23
  USE_LOCAL_DDB = os.getenv("USE_LOCAL_DDB", "false").lower() == "true"
24
 
25
  logger = logging.getLogger("uvicorn")
@@ -113,7 +115,7 @@ def create_environmental_table_if_not_exists(dynamodb):
113
  global environment_table
114
  try:
115
  environment_table = dynamodb.create_table(
116
- TableName=ENVIRONMENT_IMPACT_TABLE,
117
  # Schema for Single Table Design
118
  KeySchema=[
119
  {
@@ -134,7 +136,7 @@ def create_environmental_table_if_not_exists(dynamodb):
134
  )
135
 
136
  # Wait for the table to be created before moving on
137
- logger.info(f"Creating table {ENVIRONMENT_IMPACT_TABLE}...")
138
  environment_table.wait_until_exists()
139
  logger.info("Table is now ACTIVE.")
140
  return environment_table
@@ -142,9 +144,9 @@ def create_environmental_table_if_not_exists(dynamodb):
142
  except ClientError as e:
143
  if e.response["Error"]["Code"] == "ResourceInUseException":
144
  logger.info(
145
- f"Table {ENVIRONMENT_IMPACT_TABLE} already exists. Skipping creation."
146
  )
147
- return dynamodb.Table(ENVIRONMENT_IMPACT_TABLE)
148
  else:
149
  raise e
150
 
 
19
  AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY", None)
20
  DYNAMODB_ENDPOINT = os.getenv("DYNAMODB_ENDPOINT", None)
21
  DDB_TABLE = os.getenv("DDB_TABLE", "chatbot-conversations")
22
+ DDB_ENVIRONMENT_IMPACT_TABLE = os.getenv(
23
+ "DDB_ENVIRONMENT_IMPACT_TABLE", "environmental-impact"
24
+ )
25
  USE_LOCAL_DDB = os.getenv("USE_LOCAL_DDB", "false").lower() == "true"
26
 
27
  logger = logging.getLogger("uvicorn")
 
115
  global environment_table
116
  try:
117
  environment_table = dynamodb.create_table(
118
+ TableName=DDB_ENVIRONMENT_IMPACT_TABLE,
119
  # Schema for Single Table Design
120
  KeySchema=[
121
  {
 
136
  )
137
 
138
  # Wait for the table to be created before moving on
139
+ logger.info(f"Creating table {DDB_ENVIRONMENT_IMPACT_TABLE}...")
140
  environment_table.wait_until_exists()
141
  logger.info("Table is now ACTIVE.")
142
  return environment_table
 
144
  except ClientError as e:
145
  if e.response["Error"]["Code"] == "ResourceInUseException":
146
  logger.info(
147
+ f"Table {DDB_ENVIRONMENT_IMPACT_TABLE} already exists. Skipping creation."
148
  )
149
+ return dynamodb.Table(DDB_ENVIRONMENT_IMPACT_TABLE)
150
  else:
151
  raise e
152