in parquet_flask/aws/aws_ddb.py [0:0]
def create_table(self, gsi_list=[]):
"""
ref: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Client.create_table
:param gsi_list: list - [{'IndexName': 'string','KeySchema': [{'AttributeName': 'string','KeyType': 'HASH'|'RANGE'},]}]
:param primary_key: str - Hash Key
:param secondary_key: str - Range Key (optional)
:param primary_key_type: str - 'S', 'N', or 'B'
:param secondary_key_type: str - 'S', 'N', or 'B'
:return: dict - create table result
"""
if self.__props.tbl_name is None:
raise ValueError('missing tbl_name')
if self.__props.hash_key is None:
raise ValueError('missing hash_key')
LOGGER.info('creating a table: {}'.format(self.__props.tbl_name))
attribute_definitions = [
{
'AttributeName': self.__props.hash_key,
'AttributeType': self.__props.hash_key_type,
}
]
key_schema = [
{
'AttributeName': self.__props.hash_key,
'KeyType': 'HASH', # 'RANGE' if there is secondary key
}
]
for each in gsi_list:
each['Projection'] = {'ProjectionType': 'ALL'}
if self.__props.range_key is not None:
attribute_definitions.append({
'AttributeName': self.__props.range_key,
'AttributeType': self.__props.range_key_type,
})
key_schema.append({
'AttributeName': self.__props.range_key,
'KeyType': 'RANGE',
})
create_tbl_params = {
'TableName': self.__props.tbl_name,
'AttributeDefinitions': attribute_definitions,
'KeySchema': key_schema,
'BillingMode': 'PAY_PER_REQUEST', # TODO setting it to on-demand. might need to re-visit later
'SSESpecification': {'Enabled': False} # TODO had to disable it since it does not support 'AES256' yet.
}
if len(gsi_list) > 0:
create_tbl_params['GlobalSecondaryIndexes'] = gsi_list
create_result = self._ddb_client.create_table(**create_tbl_params)
return create_result