|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Set variables |
| 4 | +FUNCTION_NAME_CUSTOM_PROFILER_OPTIONS="aws-lambda-java-profiler-function-custom-profiler-options-${GITHUB_RUN_ID}" |
| 5 | +PAYLOAD='{"key": "value"}' |
| 6 | + |
| 7 | +# Expected profiler commands (should match create_function.sh) |
| 8 | +EXPECTED_START_COMMAND="start,event=wall,interval=1us" |
| 9 | +EXPECTED_STOP_COMMAND="stop,file=%s,include=*AWSLambda.main,include=start_thread" |
| 10 | + |
| 11 | +echo "Invoking Lambda function with custom profiler options: $FUNCTION_NAME_CUSTOM_PROFILER_OPTIONS" |
| 12 | + |
| 13 | +# Invoke the Lambda function synchronously and capture the response |
| 14 | +RESPONSE=$(aws lambda invoke \ |
| 15 | + --function-name "$FUNCTION_NAME_CUSTOM_PROFILER_OPTIONS" \ |
| 16 | + --payload "$PAYLOAD" \ |
| 17 | + --cli-binary-format raw-in-base64-out \ |
| 18 | + --log-type Tail \ |
| 19 | + output.json) |
| 20 | + |
| 21 | +# Extract the status code and log result from the response |
| 22 | +STATUS_CODE=$(echo "$RESPONSE" | jq -r '.StatusCode') |
| 23 | +LOG_RESULT=$(echo "$RESPONSE" | jq -r '.LogResult') |
| 24 | + |
| 25 | +echo "Function invocation completed with status code: $STATUS_CODE" |
| 26 | + |
| 27 | +# Decode and display the logs |
| 28 | +if [ -n "$LOG_RESULT" ]; then |
| 29 | + echo "Function logs:" |
| 30 | + echo "$LOG_RESULT" | base64 --decode |
| 31 | +else |
| 32 | + echo "No logs available." |
| 33 | +fi |
| 34 | + |
| 35 | +# Display the function output |
| 36 | +echo "Function output:" |
| 37 | +cat output.json |
| 38 | + |
| 39 | +# Verify profiler started |
| 40 | +echo "$LOG_RESULT" | base64 --decode | grep "starting the profiler for coldstart" || exit 1 |
| 41 | + |
| 42 | +# Verify custom start command is being used |
| 43 | +echo "$LOG_RESULT" | base64 --decode | grep "$EXPECTED_START_COMMAND" || exit 1 |
| 44 | + |
| 45 | +# Verify no upload on cold start |
| 46 | +echo "$LOG_RESULT" | base64 --decode | grep -v "uploading" || exit 1 |
| 47 | + |
| 48 | +# Clean up the output file |
| 49 | +rm output.json |
| 50 | + |
| 51 | + |
| 52 | +# Invoke it a second time for warm start |
| 53 | +echo "Invoking Lambda function (warm start): $FUNCTION_NAME_CUSTOM_PROFILER_OPTIONS" |
| 54 | + |
| 55 | +# Invoke the Lambda function synchronously and capture the response |
| 56 | +RESPONSE=$(aws lambda invoke \ |
| 57 | + --function-name "$FUNCTION_NAME_CUSTOM_PROFILER_OPTIONS" \ |
| 58 | + --payload "$PAYLOAD" \ |
| 59 | + --cli-binary-format raw-in-base64-out \ |
| 60 | + --log-type Tail \ |
| 61 | + output.json) |
| 62 | + |
| 63 | +# Extract the status code and log result from the response |
| 64 | +STATUS_CODE=$(echo "$RESPONSE" | jq -r '.StatusCode') |
| 65 | +LOG_RESULT=$(echo "$RESPONSE" | jq -r '.LogResult') |
| 66 | + |
| 67 | +echo "Function invocation completed with status code: $STATUS_CODE" |
| 68 | + |
| 69 | +# Decode and display the logs |
| 70 | +if [ -n "$LOG_RESULT" ]; then |
| 71 | + echo "Function logs:" |
| 72 | + echo "$LOG_RESULT" | base64 --decode |
| 73 | +else |
| 74 | + echo "No logs available." |
| 75 | +fi |
| 76 | + |
| 77 | +# Display the function output |
| 78 | +echo "Function output:" |
| 79 | +cat output.json |
| 80 | + |
| 81 | +# Verify upload happens on warm start |
| 82 | +echo "$LOG_RESULT" | base64 --decode | grep "uploading" || exit 1 |
| 83 | + |
| 84 | +# Verify custom stop command is being used |
| 85 | +echo "$LOG_RESULT" | base64 --decode | grep "$EXPECTED_STOP_COMMAND" || exit 1 |
| 86 | + |
| 87 | +# Clean up the output file |
| 88 | +rm output.json |
0 commit comments