AWS Security ChangesHomeSearch

AWS ec2 high security documentation change

Service: ec2 · 2026-05-01 · Security-related high

File: ec2/latest/devguide/example_ecs_GettingStarted_018_section.md

Summary

Added multiple security enhancements to ECS setup example: CIDR restriction warnings, JSON validation for trust policies, user-data script validation, IMDSv2 enforcement, secure placeholder handling, CloudWatch logging, and automated cleanup.

Security assessment

Changes explicitly address security weaknesses: 1) Added warnings about open CIDR ranges (0.0.0.0/0) with production risks, 2) Implemented JSON validation to prevent malformed trust policies, 3) Added script validation to block faulty user-data execution, 4) Enforced IMDSv2 to mitigate SSRF vulnerabilities, 5) Secured placeholder handling to prevent injection, 6) Added logging for audit trails. Comments like 'SECURITY FIX' provide direct evidence.

Diff

diff --git a/ec2/latest/devguide/example_ecs_GettingStarted_018_section.md b/ec2/latest/devguide/example_ecs_GettingStarted_018_section.md
index 99fce5129..4292a0a64 100644
--- a//ec2/latest/devguide/example_ecs_GettingStarted_018_section.md
+++ b//ec2/latest/devguide/example_ecs_GettingStarted_018_section.md
@@ -280 +280,3 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        # Add HTTP access rule for nginx web server
+        # Add HTTP access rule for nginx web server with restricted CIDR
+        # SECURITY FIX: Restrict access to specific CIDR if available, otherwise document the risk
+        log "WARNING: Security group allows HTTP (port 80) from 0.0.0.0/0 - restrict this in production"
@@ -330,0 +333,7 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+            # SECURITY FIX: Validate JSON before using
+            if ! jq empty ecs-instance-trust-policy.json 2>/dev/null; then
+                log "ERROR: Invalid JSON in trust policy"
+                rm -f ecs-instance-trust-policy.json
+                exit 1
+            fi
+            
@@ -371,0 +381,7 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+        # SECURITY FIX: Validate user data script before use
+        if ! bash -n ecs-user-data.sh 2>/dev/null; then
+            log "ERROR: Invalid user data script"
+            rm -f ecs-user-data.sh
+            exit 1
+        fi
+        
@@ -380,0 +397,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+            --monitoring Enabled=false \
+            --metadata-options HttpTokens=required,HttpPutResponseHopLimit=1 \
@@ -384,0 +403 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+            rm -f ecs-user-data.sh
@@ -388,0 +408 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+        log "Instance metadata options: IMDSv2 enforced with hop limit 1"
@@ -413,0 +434 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+            rm -f ecs-user-data.sh
@@ -425 +446 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        cat > task-definition.json << EOF
+        cat > task-definition.json << 'EOF'
@@ -427 +448 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        "family": "$TASK_FAMILY",
+        "family": "TASK_FAMILY_PLACEHOLDER",
@@ -441 +462,9 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-                ]
+                ],
+                "logConfiguration": {
+                    "logDriver": "awslogs",
+                    "options": {
+                        "awslogs-group": "/ecs/nginx-task",
+                        "awslogs-region": "REGION_PLACEHOLDER",
+                        "awslogs-stream-prefix": "ecs"
+                    }
+                }
@@ -448,0 +478,4 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+        # Replace placeholders securely
+        sed -i "s|TASK_FAMILY_PLACEHOLDER|$TASK_FAMILY|g" task-definition.json
+        sed -i "s|REGION_PLACEHOLDER|$AWS_REGION|g" task-definition.json
+        
@@ -451,0 +485 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+            rm -f task-definition.json
@@ -460,0 +495 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+            rm -f task-definition.json
@@ -464,0 +500 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+        log "Task definition includes CloudWatch Logs configuration for monitoring"
@@ -566,0 +603 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+        log "Security improvements: IMDSv2 enforced, JSON validation, input sanitization, CloudWatch Logs configured"
@@ -601,4 +638 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        echo "Do you want to clean up all created resources? (y/n): "
-        read -r CLEANUP_CHOICE
-        
-        if [[ "$CLEANUP_CHOICE" =~ ^[Yy]$ ]]; then
+        log "Auto-confirming cleanup - proceeding with resource cleanup"
@@ -607,13 +640,0 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        else
-            log "Resources left running. Remember to clean them up manually to avoid charges."
-            echo ""
-            echo "To clean up manually later, run these commands:"
-            echo "  aws ecs update-service --cluster $CLUSTER_NAME --service $SERVICE_NAME --desired-count 0"
-            echo "  aws ecs delete-service --cluster $CLUSTER_NAME --service $SERVICE_NAME"
-            echo "  aws ecs delete-cluster --cluster $CLUSTER_NAME"
-            echo "  aws ec2 terminate-instances --instance-ids $INSTANCE_ID"
-            echo "  aws ec2 delete-security-group --group-id $SECURITY_GROUP_ID"
-            echo "  aws ec2 delete-key-pair --key-name $KEY_PAIR_NAME"
-        fi
-        
-        log "Script execution completed"