Skip to content

Commit 4834e99

Browse files
Merge pull request #6 from Mipmipp/doc/dynamodb-scripts
Documentation: DynamoDB scripts.
2 parents 4c9eed4 + ffdd03d commit 4834e99

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed
+26-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
11
#!/bin/sh
22

3-
aws dynamodb put-item \
3+
# LOCALSTACK DYNAMODB DOCUMENTATION RESOURCE: https://docs.localstack.cloud/user-guide/aws/dynamodb/
4+
5+
# Function to handle failures and exit the script
6+
fail() {
7+
echo "$2"
8+
exit $1
9+
}
10+
11+
# Function to execute a command and display its output
12+
execute() {
13+
OUTPUT=$( "$@" 2>&1 ) # Capture the output and errors
14+
echo "$OUTPUT" # Display the output
15+
if [ $? -ne 0 ]; then # Check if there was an error
16+
fail 1 "Error: $OUTPUT"
17+
fi
18+
}
19+
20+
# Seed the 'items' table with default items
21+
echo "Seeding the 'items' table with default items..."
22+
23+
execute aws dynamodb put-item \
424
--table-name items \
525
--item '{
6-
"id": {"S": "'$(uuidgen 2>/dev/null || echo "1")'"},
26+
"id": {"S": "1"},
727
"name": {"S": "Premium Service Package"},
828
"description": {"S": "A comprehensive package offering premium services including dedicated support and priority access."},
929
"createdAt": {"S": "'$(date -u +"%Y-%m-%dT%H:%M:%SZ")'"}
1030
}' \
1131
--endpoint-url http://localhost:4566
1232

13-
aws dynamodb put-item \
33+
execute aws dynamodb put-item \
1434
--table-name items \
1535
--item '{
16-
"id": {"S": "'$(uuidgen 2>/dev/null || echo "2")'"},
36+
"id": {"S": "2"},
1737
"name": {"S": "Standard Service Package"},
1838
"description": {"S": "A standard package providing essential services with regular support."},
1939
"createdAt": {"S": "'$(date -u +"%Y-%m-%dT%H:%M:%SZ")'"}
2040
}' \
2141
--endpoint-url http://localhost:4566
42+
43+
echo "Items seeded successfully."
+21-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
#!/bin/sh
22

3-
aws dynamodb create-table \
3+
# LOCALSTACK DYNAMODB DOCUMENTATION RESOURCE: https://docs.localstack.cloud/user-guide/aws/dynamodb/
4+
5+
# Function to handle failures and exit the script
6+
fail() {
7+
echo "$2"
8+
exit $1
9+
}
10+
11+
# Function to execute a command and display its output
12+
execute() {
13+
OUTPUT=$( "$@" 2>&1 ) # Capture the output and errors
14+
echo "$OUTPUT" # Display the output
15+
if [ $? -ne 0 ]; then # Check if there was an error
16+
fail 1 "Error: $OUTPUT"
17+
fi
18+
}
19+
20+
# Create a DynamoDB table named 'items' with a primary key 'id'
21+
echo "Creating the DynamoDB table 'items'..."
22+
execute aws dynamodb create-table \
423
--table-name items \
524
--key-schema AttributeName=id,KeyType=HASH \
625
--attribute-definitions \
726
AttributeName=id,AttributeType=S \
827
--billing-mode PAY_PER_REQUEST \
928
--endpoint-url http://localhost:4566
29+
echo "Done successfully."

0 commit comments

Comments
 (0)