-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_table.py
More file actions
52 lines (46 loc) · 1.59 KB
/
create_table.py
File metadata and controls
52 lines (46 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
import boto3
dynamodb = boto3.client(
'dynamodb',
endpoint_url='http://localhost:8000',
region_name='ap-northeast-2',
aws_access_key_id='test',
aws_secret_access_key='test'
)
table_name = 'dailydevq-dev-users'
try:
# 기존 테이블 확인
existing_tables = dynamodb.list_tables()['TableNames']
if table_name in existing_tables:
print(f'✅ 테이블이 이미 존재합니다: {table_name}')
else:
# 테이블 생성
response = dynamodb.create_table(
TableName=table_name,
KeySchema=[
{'AttributeName': 'id', 'KeyType': 'HASH'}
],
AttributeDefinitions=[
{'AttributeName': 'id', 'AttributeType': 'S'},
{'AttributeName': 'email', 'AttributeType': 'S'}
],
GlobalSecondaryIndexes=[
{
'IndexName': 'email-index',
'KeySchema': [{'AttributeName': 'email', 'KeyType': 'HASH'}],
'Projection': {'ProjectionType': 'ALL'},
'ProvisionedThroughput': {
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5
}
}
],
ProvisionedThroughput={
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5
}
)
print(f'✅ 테이블 생성 완료: {table_name}')
print(f' Status: {response["TableDescription"]["TableStatus"]}')
except Exception as e:
print(f'❌ 오류: {str(e)}')