-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathforecast
executable file
·144 lines (95 loc) · 3.59 KB
/
forecast
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
source ./config.sh
if [[ ! "$STACK_NAME" =~ ^[a-z][a-z0-9]*$ ]]
then
echo "ERROR: STACK_NAME must start with a lower case letter and contain only lower case letters and numbers"
exit 1
fi
if ! [ -x "$(command -v aws)" ]
then
echo "ERROR: You must install the awscli"
echo "https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html"
exit 1
fi
STACK_DESCRIPTION=$(aws cloudformation describe-stacks --stack-name $STACK_NAME 2>&1)
if [[ $STACK_DESCRIPTION == *"locate credentials"* || $STACK_DESCRIPTION == *"specify a region"* ]]
then
echo "ERROR: You must set your AWS credentials/profile and default region via Environment Variables"
echo "https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html"
exit 1
fi
if [[ $STACK_DESCRIPTION == *"ValidationError"* ]]
then
echo "Initializing $STACK_NAME CloudFormation Stack (1-2 minutes)..."
aws cloudformation deploy \
--stack-name "$STACK_NAME" \
--template-file ./init.yml \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM
BUILD_PROJECT=$(aws cloudformation describe-stacks \
--stack-name "$STACK_NAME" \
--query 'Stacks[0].Outputs[?OutputKey==`BuildProject`].OutputValue' \
--output text)
echo "Building Athena/Lambda State Machine via AWS CodeBuild (3-5 minutes)..."
BUILD_ID=$(aws codebuild start-build \
--project-name "$BUILD_PROJECT" \
--query 'build.id' \
--output text)
echo "You can watch progress at the following URI:"
echo "https://console.aws.amazon.com/codesuite/codebuild/projects/$BUILD_PROJECT/build/$BUILD_ID/log"
while [ true ]
do
sleep 10
BUILD_STATUS=$(aws codebuild batch-get-builds \
--ids "$BUILD_ID" \
--query 'builds[0].buildStatus' \
--output text)
if [ "$BUILD_STATUS" != "IN_PROGRESS" ]
then
break
fi
done
if [ "$BUILD_STATUS" != "SUCCEEDED" ]
then
echo "There was a problem with the build, report the logs at the link above to the GitHub repository!"
exit 1
else
echo "Build complete!"
fi
else
echo "$STACK_NAME exists, no need to create/build..."
fi
echo "Running the Athena State Machine to generate your forecast animation (5-15 minutes)..."
ATHENA_MACHINE_ARN=$(aws cloudformation describe-stacks \
--stack-name "$STACK_NAME" \
--query 'Stacks[0].Outputs[?OutputKey==`AthenaMachineArn`].OutputValue' \
--output text)
EXECUTION_ARN=$(aws stepfunctions start-execution \
--state-machine-arn "$ATHENA_MACHINE_ARN" \
--input "{ \"NdfdElement\":\"$NDFD_ELEMENT\", \"SquareKm\":$SQUARE_KM, \"CenterLatitude\":$CENTER_LATITUDE, \"CenterLongitude\":$CENTER_LONGITUDE, \"TimeZone\":\"$TIMEZONE\" }" \
--query 'executionArn' \
--output text)
echo "You can watch progress at the following URI:"
echo "https://console.aws.amazon.com/states/home?region=$AWS_REGION#/executions/details/$EXECUTION_ARN"
while [ true ]
do
sleep 10
EXECUTION_STATUS=$(aws stepfunctions describe-execution \
--execution-arn "$EXECUTION_ARN" \
--query 'status' \
--output text)
if [ "$EXECUTION_STATUS" != "RUNNING" ]
then
break
fi
done
if [ "$EXECUTION_STATUS" != "SUCCEEDED" ]
then
echo "There was a problem with generating the animation, report the logs at the link above to the GitHub repository!"
exit 1
fi
echo "Your forecast animation has been generated! View it at the following link!"
ANIMATION_URI=$(aws cloudformation describe-stacks \
--stack-name "$STACK_NAME" \
--query 'Stacks[0].Outputs[?OutputKey==`AnimationUri`].OutputValue' \
--output text)
echo "$ANIMATION_URI"