Skip to content

Commit 5b89af0

Browse files
committed
Fix 081-mediaconnect: local-outside-fn, jq path, ARN regex — passes locally
1 parent 6753d60 commit 5b89af0

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

tuts/081-aws-elemental-mediaconnect-gs/aws-elemental-mediaconnect-gs.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ cleanup_resources() {
7777

7878
if [ -n "${FLOW_ARN:-}" ]; then
7979
# Security: Validate ARN format before using it
80-
if [[ ! "$FLOW_ARN" =~ ^arn:aws:mediaconnect:[a-z0-9-]+:[0-9]+:flow:[a-zA-Z0-9-]+$ ]]; then
80+
if [[ ! "$FLOW_ARN" =~ ^arn:aws:mediaconnect:[a-z0-9-]+:[0-9]+:flow:[a-zA-Z0-9:-]+$ ]]; then
8181
echo "WARNING: Invalid Flow ARN format, skipping cleanup: $FLOW_ARN"
8282
return 1
8383
fi
@@ -192,14 +192,17 @@ else
192192
fi
193193

194194
# Extract the flow ARN from the output
195-
FLOW_ARN=$(extract_json_value "$create_flow_output" "FlowArn")
195+
FLOW_ARN=$(echo "$create_flow_output" | jq -r '.Flow.FlowArn // empty' 2>/dev/null)
196+
if [ -z "$FLOW_ARN" ]; then
197+
FLOW_ARN=$(echo "$create_flow_output" | grep -o '"FlowArn": "[^"]*' | head -1 | cut -d'"' -f4)
198+
fi
196199
if [ -z "$FLOW_ARN" ]; then
197200
handle_error "Failed to extract flow ARN from output"
198201
fi
199202
echo "Flow ARN: $FLOW_ARN"
200203

201204
# Validate flow ARN format
202-
if [[ ! "$FLOW_ARN" =~ ^arn:aws:mediaconnect:[a-z0-9-]+:[0-9]+:flow:[a-zA-Z0-9-]+$ ]]; then
205+
if [[ ! "$FLOW_ARN" =~ ^arn:aws:mediaconnect:[a-z0-9-]+:[0-9]+:flow:[a-zA-Z0-9:-]+$ ]]; then
203206
handle_error "Invalid Flow ARN format: $FLOW_ARN"
204207
fi
205208

@@ -216,7 +219,8 @@ fi
216219

217220
# Extract the output ARN
218221
output_arn=""
219-
output_arn=$(extract_json_value "$add_output_output" "OutputArn")
222+
output_arn=$(echo "$add_output_output" | jq -r ".Output.OutputArn // empty" 2>/dev/null)
223+
if [ -z "$output_arn" ]; then output_arn=$(echo "$add_output_output" | grep -o '"OutputArn": "[^"]*' | head -1 | cut -d'"' -f4); fi
220224
if [ -z "$output_arn" ]; then
221225
echo "WARNING: Failed to extract output ARN from output"
222226
else
@@ -237,7 +241,10 @@ fi
237241

238242
# Extract the entitlement ARN
239243
entitlement_arn=""
240-
entitlement_arn=$(extract_json_value "$grant_entitlement_output" "EntitlementArn")
244+
entitlement_arn=$(echo "$grant_entitlement_output" | jq -r '.Entitlement.EntitlementArn // empty' 2>/dev/null)
245+
if [ -z "$entitlement_arn" ]; then
246+
entitlement_arn=$(echo "$grant_entitlement_output" | grep -o '"EntitlementArn": "[^"]*' | head -1 | cut -d'"' -f4)
247+
fi
241248
if [ -z "$entitlement_arn" ]; then
242249
echo "WARNING: Failed to extract entitlement ARN from output"
243250
else

0 commit comments

Comments
 (0)