Skip to content

Commit 16511c2

Browse files
authored
Merge pull request #79 from aws-samples/fix/logging-race-condition
Fix logging race condition in 2 scripts
2 parents fa9b058 + 129a5a0 commit 16511c2

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

tuts/049-aws-end-user-messaging-gs/aws-end-user-messaging-gs.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,16 @@
1010
#
1111
# Usage: ./aws-end-user-messaging-gs.sh [--auto-cleanup]
1212

13-
set -euo pipefail
13+
set -uo pipefail
1414

1515
# Security: Set secure umask for created files
1616
umask 0077
1717

18-
# Set up logging with secure file permissions
19-
LOG_DIR="${XDG_STATE_HOME:-.}/aws-eump-logs"
18+
# Set up logging
19+
LOG_DIR="./aws-eump-logs"
2020
mkdir -p "$LOG_DIR"
21-
chmod 700 "$LOG_DIR"
22-
2321
LOG_FILE="$LOG_DIR/aws-end-user-messaging-push-script-$(date +%Y%m%d-%H%M%S).log"
2422
exec > >(tee -a "$LOG_FILE") 2>&1
25-
chmod 600 "$LOG_FILE"
2623

2724
echo "Starting AWS End User Messaging Push setup script..."
2825
echo "Logging to $LOG_FILE"
@@ -38,7 +35,7 @@ cleanup() {
3835
echo "Cleaning up temporary resources..."
3936

4037
# Remove temporary files securely
41-
for temp_file in "${TEMP_FILES[@]}"; do
38+
for temp_file in "${TEMP_FILES[@]+"${TEMP_FILES[@]}"}"; do
4239
if [ -f "$temp_file" ]; then
4340
shred -vfz -n 3 "$temp_file" 2>/dev/null || rm -f "$temp_file"
4441
fi
@@ -142,7 +139,7 @@ validate_permissions() {
142139
echo "Validating IAM permissions..."
143140

144141
# Test basic Pinpoint permissions
145-
if ! aws pinpoint get-apps &> /dev/null; then
142+
if ! aws pinpoint get-apps > /dev/null 2>&1; then
146143
echo "WARNING: Unable to list Pinpoint applications." >&2
147144
echo "Please ensure you have appropriate IAM permissions for Pinpoint operations." >&2
148145
echo "Required permissions:" >&2

tuts/070-amazon-dynamodb-gs/amazon-dynamodb-gs.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ LOG_DIR="${XDG_STATE_HOME:-.}/dynamodb-tutorial-logs"
1616
mkdir -p "$LOG_DIR"
1717
LOG_FILE="$LOG_DIR/dynamodb-tutorial-$(date +%Y%m%d-%H%M%S).log"
1818
chmod 700 "$LOG_DIR"
19-
exec > >(tee -a "$LOG_FILE") 2>&1
19+
touch "$LOG_FILE"
2020
chmod 600 "$LOG_FILE"
21+
exec > >(tee -a "$LOG_FILE") 2>&1
2122

2223
echo "Starting DynamoDB Getting Started Tutorial at $(date)"
2324
echo "Logging to $LOG_FILE"

0 commit comments

Comments
 (0)