-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute.sh
More file actions
executable file
·67 lines (53 loc) · 1.75 KB
/
execute.sh
File metadata and controls
executable file
·67 lines (53 loc) · 1.75 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
set -e
REGION=${AWS_REGION:-ap-east-1}
STACK_NAME="s3-batch-processor"
WORKER_COUNT=${1:-3}
if [ "$#" -eq 0 ]; then
echo "Usage: $0 <worker_count> [prefix]"
echo "Example: $0 5 input/"
echo "Example: $0 10 data/"
exit 1
fi
PREFIX=${2:-input/}
echo "🚀 Executing S3 Batch Processing with $WORKER_COUNT workers"
# Get stack outputs
BUCKET_NAME=$(aws cloudformation describe-stacks \
--stack-name $STACK_NAME \
--region $REGION \
--query 'Stacks[0].Outputs[?OutputKey==`BucketName`].OutputValue' \
--output text)
STATE_MACHINE_ARN=$(aws cloudformation describe-stacks \
--stack-name $STACK_NAME \
--region $REGION \
--query 'Stacks[0].Outputs[?OutputKey==`StateMachineArn`].OutputValue' \
--output text)
echo "📋 Using:"
echo " Bucket: $BUCKET_NAME"
echo " Prefix: $PREFIX"
echo " Workers: $WORKER_COUNT"
# Get objects to process
OBJECTS=$(aws s3api list-objects-v2 \
--bucket $BUCKET_NAME \
--prefix $PREFIX \
--region $REGION \
--query 'Contents[].{Key: Key}')
OBJECT_COUNT=$(echo "$OBJECTS" | jq length)
echo " Objects: $OBJECT_COUNT"
if [ "$OBJECT_COUNT" -eq 0 ]; then
echo "❌ No objects found with prefix '$PREFIX'"
exit 1
fi
# Create execution input
EXECUTION_INPUT=$(echo "$OBJECTS" | jq --argjson workers "$WORKER_COUNT" '{objects: ., worker_count: $workers}')
# Execute workflow
echo ""
echo "🚀 Starting Step Functions execution..."
EXECUTION_ARN=$(aws stepfunctions start-execution \
--state-machine-arn "$STATE_MACHINE_ARN" \
--input "$EXECUTION_INPUT" \
--region $REGION \
--query 'executionArn' \
--output text)
echo "✅ Execution started: $EXECUTION_ARN"
echo "📊 Monitor at: https://$REGION.console.aws.amazon.com/states/home?region=$REGION#/executions/details/$EXECUTION_ARN"