@@ -3,12 +3,12 @@ export AWS_SECRET_ACCESS_KEY ?= test
3
3
export AWS_DEFAULT_REGION =us-east-1
4
4
SHELL := /bin/bash
5
5
6
- # # Show this help
7
- usage :
8
- @fgrep -h " ##" $(MAKEFILE_LIST ) | fgrep -v fgrep | sed -e ' s/\\$$//' | sed -e ' s/##//'
6
+ usage : # # Show this help in table format
7
+ @echo " | Target | Description |"
8
+ @echo " |------------------------|-------------------------------------------------------------------|"
9
+ @fgrep -h " ##" $(MAKEFILE_LIST ) | fgrep -v fgrep | sed -e ' s/:.*##\s*/##/g' | awk -F' ##' ' { printf "| %-22s | %-65s |\n", $$1, $$2 }'
9
10
10
- # # Check if all required prerequisites are installed
11
- check :
11
+ check : # # Check if all required prerequisites are installed
12
12
@command -v docker > /dev/null 2>&1 || { echo " Docker is not installed. Please install Docker and try again." ; exit 1; }
13
13
@command -v node > /dev/null 2>&1 || { echo " Node.js is not installed. Please install Node.js and try again." ; exit 1; }
14
14
@command -v aws > /dev/null 2>&1 || { echo " AWS CLI is not installed. Please install AWS CLI and try again." ; exit 1; }
19
19
@command -v awslocal > /dev/null 2>&1 || { echo " awslocal is not installed. Please install awslocal and try again." ; exit 1; }
20
20
@echo " All required prerequisites are available."
21
21
22
- # # Install dependencies
23
- install :
22
+ install : # # Install all required dependencies
24
23
@if [ ! -d " node_modules" ]; then \
25
24
echo " node_modules not found. Running npm install..." ; \
26
25
npm install; \
@@ -31,39 +30,51 @@ install:
31
30
fi
32
31
@echo " All required dependencies are available."
33
32
34
- # # Deploy the infrastructure
35
- deploy :
33
+ deploy : # # Deploy the CDK stack
36
34
@echo " Bootstrapping CDK..."
37
35
cdklocal bootstrap
38
36
@echo " Deploying CDK..."
39
37
cdklocal deploy --require-approval never
40
38
@echo " CDK deployed successfully."
41
39
42
- # # Run the tests
43
- test :
40
+ test : # # Run the tests
44
41
@echo " Running tests..."
45
42
npm test
46
43
@echo " Tests completed successfully."
47
44
48
- # # Start LocalStack in detached mode
49
- start :
45
+ run : # # Execute a SQL query through the Lambda function
46
+ @echo " Executing SQL query through Lambda function..."
47
+ @aws_version=$$(aws --version | grep -o "aws-cli/[0-9]*" | cut -d'/' -f2 ) ; \
48
+ if [ " $$ aws_version" = " 2" ]; then \
49
+ echo " Using AWS CLI version 2 command format..." ; \
50
+ awslocal lambda invoke \
51
+ --cli-binary-format raw-in-base64-out \
52
+ --function-name my-lambda-rds-query-helper \
53
+ --payload ' {"sqlQuery": "select Author from books", "secretName":"/rdsinitexample/rds/creds/mysql-01"}' output; \
54
+ else \
55
+ echo " Using AWS CLI version 1 command format..." ; \
56
+ awslocal lambda invoke \
57
+ --function-name my-lambda-rds-query-helper \
58
+ --payload ' {"sqlQuery": "select Author from books", "secretName":"/rdsinitexample/rds/creds/mysql-01"}' output; \
59
+ fi
60
+ @echo " Query execution completed. Results:"
61
+ @cat output
62
+
63
+ start : # # Start LocalStack in detached mode
50
64
@echo " Starting LocalStack..."
51
65
@LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN ) localstack start -d
52
66
@echo " LocalStack started successfully."
53
67
54
- # # Stop the Running LocalStack container
55
- stop :
68
+ stop : # # Stop LocalStack
56
69
@echo " Stopping LocalStack..."
57
70
@localstack stop
58
71
@echo " LocalStack stopped successfully."
59
72
60
- # # Make sure the LocalStack container is up
61
- ready :
73
+ ready : # # Wait for LocalStack to be ready
62
74
@echo Waiting on the LocalStack container...
63
75
@localstack wait -t 30 && echo LocalStack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1)
64
76
65
- # # Save the logs in a separate file
66
- logs :
77
+ logs : # # Get LocalStack logs
67
78
@localstack logs > logs.txt
68
79
69
80
.PHONY : usage check start ready install deploy test logs stop
0 commit comments