-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_app_to-S3.sh
More file actions
56 lines (38 loc) · 1.87 KB
/
deploy_app_to-S3.sh
File metadata and controls
56 lines (38 loc) · 1.87 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
#!/bin/bash
# Get user input for stack name
read -p "Enter the name of the CloudFormation stack (default=postcode-api-stack): " stack_name
stack_name=${stack_name:-postcode-api-stack}
# Get user input for aws profile
read -p "Enter the name of the aws profile (default=dev-1): " aws_profile
aws_profile=${aws_profile:-dev-1}
# Get user input for aws bucket name
read -p "Enter the name of the aws bucket name for static website (default=postcode-app-bucket): " bucket_name
bucket_name=${bucket_name:-postcode-app-bucket}
static_website_stack_name=hosting-bucket
# Get the API Gateway URL from the stack
api_gateway_endpoint=$(aws cloudformation describe-stacks --stack-name "$stack_name" --profile $aws_profile --query "Stacks[0].Outputs[?OutputKey=='PostcodeApi'].OutputValue" --output text)
# Get the S3 Bucket Name from the stack
#s3_bucket_name=$(aws cloudformation get-template --stack-name "$stack_name" --profile $aws_profile --query "TemplateBody.Resources.PostcodeApiFunction.Properties.Code.S3Bucket" --output text)
# Output the results
echo "API Gateway URL: $api_gateway_endpoint"
echo "S3 Bucket Name: $bucket_name"
# install
npm install
# Create .env file for building
touch .env
# Add the API Gateway endpoint to the .env file
echo "REACT_APP_GATEWAY_API_URL=$api_gateway_endpoint" > .env
# Confirm that the endpoint has been added to the .env file
echo "The API Gateway endpoint has been added to the .env file:"
cat .env
# This is necessary otherwise the stack-delelte command fails
aws s3 rm s3://$bucket_name --recursive --profile $aws_profile
# Create distribution for deployment
npm run build
# remove any stack if it exists
aws cloudformation delete-stack --profile $aws_profile --stack-name $static_website_stack_name
npm run provision
cd build/
# Sync distribution with S3
aws s3 sync . s3://$bucket_name/ --profile $aws_profile
read -p "Press Enter to exit this script" exit