Skip to content

Commit de3b74e

Browse files
author
Dennis Kieselhorst
authored
Merge pull request #1123 from lefkarag/db_setup_handle_error
Return error exit code when db setup Lambda function fails
2 parents b6c6344 + d3112d9 commit de3b74e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

labs/unicorn-store/infrastructure/db-setup/src/main/java/com/amazon/aws/DBSetupHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEv
6565
.withBody("DB Setup successful");
6666
}
6767
}
68-
} catch (SQLException | IOException sqlException) {
68+
} catch (Exception sqlException) {
6969
logger.error("Error connection to the database:" + sqlException.getMessage());
7070
return new APIGatewayProxyResponseEvent()
7171
.withStatusCode(500)

labs/unicorn-store/setup-infrastructure.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ cdk bootstrap
1919
cdk deploy UnicornStoreInfrastructure --require-approval never --outputs-file target/output.json
2020

2121
# Execute the DB Setup function to create the table
22-
aws lambda invoke --function-name $(cat target/output.json | jq -r '.UnicornStoreInfrastructure.DbSetupArn') /dev/stdout | cat;
22+
lambda_result=$(aws lambda invoke --function-name $(cat target/output.json | jq -r '.UnicornStoreInfrastructure.DbSetupArn') /dev/stdout 2>&1)
23+
# Extract the status code from the response payload
24+
lambda_status_code=$(echo "$lambda_result" | jq 'first(.. | objects | select(has("statusCode"))) | .statusCode')
25+
26+
if [ "$lambda_status_code" == "200" ]; then
27+
echo "DB Setup Lambda function executed successfully"
28+
else
29+
echo "DB Setup Lambda function execution failed"
30+
exit 1
31+
fi
2332

2433
cd ~/environment/aws-lambda-java-workshop/labs/unicorn-store
2534
./setup-vpc-peering.sh

0 commit comments

Comments
 (0)