|
1 | 1 | #!/bin/sh
|
2 | 2 |
|
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 \ |
4 | 24 | --table-name items \
|
5 | 25 | --item '{
|
6 |
| - "id": {"S": "'$(uuidgen 2>/dev/null || echo "1")'"}, |
| 26 | + "id": {"S": "1"}, |
7 | 27 | "name": {"S": "Premium Service Package"},
|
8 | 28 | "description": {"S": "A comprehensive package offering premium services including dedicated support and priority access."},
|
9 | 29 | "createdAt": {"S": "'$(date -u +"%Y-%m-%dT%H:%M:%SZ")'"}
|
10 | 30 | }' \
|
11 | 31 | --endpoint-url http://localhost:4566
|
12 | 32 |
|
13 |
| -aws dynamodb put-item \ |
| 33 | +execute aws dynamodb put-item \ |
14 | 34 | --table-name items \
|
15 | 35 | --item '{
|
16 |
| - "id": {"S": "'$(uuidgen 2>/dev/null || echo "2")'"}, |
| 36 | + "id": {"S": "2"}, |
17 | 37 | "name": {"S": "Standard Service Package"},
|
18 | 38 | "description": {"S": "A standard package providing essential services with regular support."},
|
19 | 39 | "createdAt": {"S": "'$(date -u +"%Y-%m-%dT%H:%M:%SZ")'"}
|
20 | 40 | }' \
|
21 | 41 | --endpoint-url http://localhost:4566
|
| 42 | + |
| 43 | +echo "Items seeded successfully." |
0 commit comments