-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·58 lines (50 loc) · 2.59 KB
/
build.sh
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
#!/bin/sh
## Set global variables
ApplicationRegion="YOUR_REGION" # AllowedPattern: [a-zA-Z0-9-]+
S3SourceBucket="YOUR_S3_BUCKET_WITH_SOURCE_CODE" # AllowedPattern: [a-zA-Z0-9-]+
S3RecordingsBucketName="THE_S3_BUCKET_SAVING_YOUR_AUDIO_RECORDINGS" # AllowedPattern: [a-zA-Z0-9-]+
S3TranscriptionBucketName="THE_S3_BUCKET_SAVING_YOUR_TRANSCRIPTIONS" # AllowedPattern: [a-zA-Z0-9-]+
DynamoDBTableName="YOUR_TABLE_NAME" # AllowedPattern: [a-zA-Z0-9-]+
SQSQueueName="YOUR_SQS_QUEUE_NAME" # AllowedPattern: [a-zA-Z0-9]+
CloudFormationStack="YOUR_CLOUD_FORMATION_STACK_NAME"
## Create S3 bucket and set parameters for CloudFormation stack
# Build your paramater string for the CFT
JSON_PARAM="ParameterKey=S3SourceBucket,ParameterValue=%s ParameterKey=DynamoDBTableName,ParameterValue=%s ParameterKey=S3RecordingsBucketName,ParameterValue=%s ParameterKey=S3TranscriptionBucketName,ParameterValue=%s ParameterKey=SQSQueueName,ParameterValue=%s"
JSON_PARAM=$(printf "$JSON_PARAM" "$S3SourceBucket" "$DynamoDBTableName" "$S3RecordingsBucketName" "$S3TranscriptionBucketName" "$SQSQueueName")
# Create your S3 bucket
if [ "$ApplicationRegion" = "us-east-1" ]; then
aws s3api create-bucket --bucket $S3SourceBucket
else
aws s3api create-bucket --bucket $S3SourceBucket --region $ApplicationRegion --create-bucket-configuration LocationConstraint=$ApplicationRegion
fi
## Code build and resource upload
# Build gradle project
echo "Build Gradle Project"
cd src/IVR-ExtractVoiceFromVideoStream/
gradle build
cd ../../
# Create resources
mkdir resources
echo "ZIP Python files"
files="IVR-AddRatings2DynamoDB IVR-Comprehend2DynamoDB IVR-SendStream2SQS IVR-TranscribeWAV2JSON"
for file in $files
do
output="../../resources/$file.zip"
cd src/$file
zip -r $output *.py
cd ../../
done
echo "Copy Gradle Build to resources"
cp src/IVR-ExtractVoiceFromVideoStream/build/distributions/IVR-ExtractVoiceFromVideoStream.zip resources/IVR-ExtractVoiceFromVideoStream.zip
# Upload resources to S3
echo "Upload files to S3"
aws s3 cp cloudformation/ivr-collect-customer-feedback.json s3://$S3SourceBucket
files="IVR-AddRatings2DynamoDB IVR-Comprehend2DynamoDB IVR-SendStream2SQS IVR-TranscribeWAV2JSON IVR-ExtractVoiceFromVideoStream"
for file in $files
do
input="resources/$file.zip"
aws s3 cp $input s3://$S3SourceBucket
done
rm -rf resources
## Run CFT stack creation
aws cloudformation create-stack --stack-name $CloudFormationStack --template-url https://$S3SourceBucket.s3.$ApplicationRegion.amazonaws.com/ivr-collect-customer-feedback.json --parameters $JSON_PARAM --capabilities CAPABILITY_NAMED_IAM --region $ApplicationRegion