|
67 | 67 | fi |
68 | 68 | echo "ARTIFACT_LOCATION=${ARTIFACT_LOCATION}" |
69 | 69 |
|
| 70 | + # Flush Firehose streams so all data is written to S3 |
| 71 | + FIREHOSE_STREAMS=$(terraform output -json firehose_delivery_stream_names 2>/dev/null | jq -r '.[] // empty' || true) |
| 72 | +
|
| 73 | + if [ -n "$FIREHOSE_STREAMS" ]; then |
| 74 | + echo "Flushing Firehose streams..." |
| 75 | +
|
| 76 | + for stream_name in $FIREHOSE_STREAMS; do |
| 77 | + echo "Reducing buffering interval for stream: $stream_name" |
| 78 | +
|
| 79 | + # Get current delivery stream config and version |
| 80 | + STREAM_DESC=$(aws firehose describe-delivery-stream --delivery-stream-name "$stream_name" 2>/dev/null || true) |
| 81 | +
|
| 82 | + if [ -n "$STREAM_DESC" ]; then |
| 83 | + VERSION_ID=$(echo "$STREAM_DESC" | jq -r '.DeliveryStreamDescription.VersionId') |
| 84 | + DEST_ID=$(echo "$STREAM_DESC" | jq -r '.DeliveryStreamDescription.Destinations[0].DestinationId') |
| 85 | +
|
| 86 | + # Update with reduced time interval (60s) to flush quickly while keeping max size (128 MiB) |
| 87 | + # Since destination type is not changing, only BufferingHints need to be specified; other config is merged |
| 88 | + aws firehose update-destination \ |
| 89 | + --delivery-stream-name "$stream_name" \ |
| 90 | + --current-delivery-stream-version-id "$VERSION_ID" \ |
| 91 | + --destination-id "$DEST_ID" \ |
| 92 | + --extended-s3-destination-update '{ |
| 93 | + "BufferingHints": { |
| 94 | + "SizeInMBs": 128, |
| 95 | + "IntervalInSeconds": 60 |
| 96 | + } |
| 97 | + }' 2>/dev/null || echo "Warning: Could not update stream $stream_name" |
| 98 | + fi |
| 99 | + done |
| 100 | +
|
| 101 | + echo "Waiting 60 seconds for Firehose to flush buffered data..." |
| 102 | + for i in 60 50 40 30 20 10; do |
| 103 | + echo " $i seconds remaining..." |
| 104 | + sleep 10 |
| 105 | + done |
| 106 | + echo " Flush complete." |
| 107 | + fi |
| 108 | +
|
70 | 109 | if [ "${TF_DESTROY_AFTER_TEST}" = "true" ]; then |
71 | 110 | # destroy resources |
72 | 111 | terraform destroy -no-color -input=false -auto-approve |
|
0 commit comments