-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
78 lines (67 loc) · 3.43 KB
/
Makefile
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
export AWS_ACCESS_KEY_ID ?= test
export AWS_SECRET_ACCESS_KEY ?= test
export AWS_DEFAULT_REGION ?= us-east-1
usage: ## Show this help
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
check: ## Check if all required prerequisites are installed
@command -v docker > /dev/null 2>&1 || { echo "Docker is not installed. Please install Docker and try again."; exit 1; }
@command -v node > /dev/null 2>&1 || { echo "Node.js is not installed. Please install Node.js and try again."; exit 1; }
@command -v aws > /dev/null 2>&1 || { echo "AWS CLI is not installed. Please install AWS CLI and try again."; exit 1; }
@command -v awslocal > /dev/null 2>&1 || { echo "AWS CLI Local (awslocal) is not installed. Please install awslocal and try again."; exit 1; }
@command -v localstack > /dev/null 2>&1 || { echo "LocalStack is not installed. Please install LocalStack and try again."; exit 1; }
@command -v zip > /dev/null 2>&1 || { echo "zip is not installed. Please install zip and try again."; exit 1; }
@echo "All required prerequisites are available."
install: ## Install dependencies and prepare environment
@echo "Installing dependencies..."
@cd feedback-survey-frontend
@npm install
@echo "Dependencies installed."
deploy-backend: ## Deploy backend resources (SSM, Lambda, and SES)
@echo "Deploying backend resources..."
awslocal ssm put-parameter --name /email/recipient --value "recipient@example.com" --type String
awslocal ssm put-parameter --name /email/sender --value "sender@example.com" --type String
awslocal ses verify-email-identity --email sender@example.com
zip -r function.zip index.js node_modules/
awslocal lambda create-function \
--function-name feedbackFormHandler \
--runtime nodejs20.x \
--handler index.handler \
--zip-file fileb://function.zip \
--role arn:aws:iam::000000000000:role/lambda-role
awslocal lambda create-function-url-config \
--function-name feedbackFormHandler \
--auth-type NONE
@echo "Backend resources deployed successfully."
deploy-frontend: ## Build and serve the frontend application
@echo "Building frontend application...";
@cd feedback-survey-frontend && npm run build
awslocal s3 mb s3://webapp
@cd feedback-survey-frontend && awslocal s3 sync --delete ./build s3://webapp
awslocal s3 website s3://webapp --index-document index.html --error-document index.html
@echo "Frontend application deployed."
@echo "Access the application at: http://webapp.s3-website.localhost.localstack.cloud:4566/"
run: ## Fetch Lambda function URL and display it
@echo "Fetching Lambda Function URL..."
FUNCTION_URL=$$(awslocal lambda get-function-url-config \
--function-name feedbackFormHandler \
--query FunctionUrl \
--output text)
@echo "Lambda Function URL: $$FUNCTION_URL"
start: ## Start LocalStack in detached mode
@echo "Starting LocalStack..."
ACTIVATE_PRO=1 localstack start -d
@echo "LocalStack started."
stop: ## Stop LocalStack
@echo "Stopping LocalStack..."
localstack stop
@echo "LocalStack stopped."
logs: ## Retrieve LocalStack logs
@localstack logs > logs.txt
@echo "Logs saved to logs.txt."
clean: ## Clean up resources
@echo "Cleaning up resources..."
awslocal lambda delete-function --function-name feedbackFormHandler || true
awslocal s3 rb s3://webapp --force || true
rm -f function.zip
@echo "Resources cleaned."
.PHONY: usage check install deploy-backend deploy-frontend run start stop logs clean