-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·48 lines (41 loc) · 1.29 KB
/
app.py
File metadata and controls
executable file
·48 lines (41 loc) · 1.29 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
import os
import boto3
def lambda_handler(event, context):
# Check if running locally
if os.environ.get('AWS_SAM_LOCAL'):
# Use local DynamoDB endpoint
dynamodb = boto3.resource('dynamodb', endpoint_url='http://172.17.0.1:8000')
else:
# Use the default DynamoDB endpoint (AWS)
dynamodb = boto3.resource('dynamodb')
# Access your DynamoDB table
table_name = dynamodb.Table(os.environ['DYNAMODB_TABLE'])
# Define the table creation parameters
table_creation_params = {
'TableName': 'CRUDLocalTable',
'KeySchema': [
{
'AttributeName': 'Id',
'KeyType': 'HASH' # Partition key
}
],
'AttributeDefinitions': [
{
'AttributeName': 'Id',
'AttributeType': 'S' # String type
}
],
'ProvisionedThroughput': {
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5
}
}
# Create the DynamoDB table
table = dynamodb.create_table(**table_creation_params)
# Wait until the table exists before continuing
table.wait_until_exists()
print("Table created successfully:", table.table_name)
return {
'statusCode': 200,
'body': table.table_name
}