@@ -3,12 +3,12 @@ export AWS_SECRET_ACCESS_KEY ?= test
33export AWS_DEFAULT_REGION =us-east-1
44SHELL := /bin/bash
55
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 }'
910
10- # # Check if all required prerequisites are installed
11- check :
11+ check : # # Check if all required prerequisites are installed
1212 @command -v docker > /dev/null 2>&1 || { echo " Docker is not installed. Please install Docker and try again." ; exit 1; }
1313 @command -v node > /dev/null 2>&1 || { echo " Node.js is not installed. Please install Node.js and try again." ; exit 1; }
1414 @command -v aws > /dev/null 2>&1 || { echo " AWS CLI is not installed. Please install AWS CLI and try again." ; exit 1; }
1919 @command -v awslocal > /dev/null 2>&1 || { echo " awslocal is not installed. Please install awslocal and try again." ; exit 1; }
2020 @echo " All required prerequisites are available."
2121
22- # # Install dependencies
23- install :
22+ install : # # Install all required dependencies
2423 @if [ ! -d " node_modules" ]; then \
2524 echo " node_modules not found. Running npm install..." ; \
2625 npm install; \
@@ -31,39 +30,51 @@ install:
3130 fi
3231 @echo " All required dependencies are available."
3332
34- # # Deploy the infrastructure
35- deploy :
33+ deploy : # # Deploy the CDK stack
3634 @echo " Bootstrapping CDK..."
3735 cdklocal bootstrap
3836 @echo " Deploying CDK..."
3937 cdklocal deploy --require-approval never
4038 @echo " CDK deployed successfully."
4139
42- # # Run the tests
43- test :
40+ test : # # Run the tests
4441 @echo " Running tests..."
4542 npm test
4643 @echo " Tests completed successfully."
4744
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
5064 @echo " Starting LocalStack..."
5165 @LOCALSTACK_AUTH_TOKEN=$(LOCALSTACK_AUTH_TOKEN ) localstack start -d
5266 @echo " LocalStack started successfully."
5367
54- # # Stop the Running LocalStack container
55- stop :
68+ stop : # # Stop LocalStack
5669 @echo " Stopping LocalStack..."
5770 @localstack stop
5871 @echo " LocalStack stopped successfully."
5972
60- # # Make sure the LocalStack container is up
61- ready :
73+ ready : # # Wait for LocalStack to be ready
6274 @echo Waiting on the LocalStack container...
6375 @localstack wait -t 30 && echo LocalStack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1)
6476
65- # # Save the logs in a separate file
66- logs :
77+ logs : # # Get LocalStack logs
6778 @localstack logs > logs.txt
6879
6980.PHONY : usage check start ready install deploy test logs stop
0 commit comments