AWS Security ChangesHomeSearch

AWS code-library documentation change

Service: code-library · 2026-05-04 · Documentation low

File: code-library/latest/ug/bash_2_ec2_code_examples.md

Summary

Added tag specifications with keys 'project' and 'tutorial' to AWS resource creation commands across multiple examples for improved resource organization and cost tracking.

Security assessment

The changes exclusively add resource tags for organizational purposes (project/tutorial identifiers). There is no evidence of security vulnerability fixes, security controls, or security feature documentation. Tags alone don't impact security posture.

Diff

diff --git a/code-library/latest/ug/bash_2_ec2_code_examples.md b/code-library/latest/ug/bash_2_ec2_code_examples.md
index fb521a53e..28aa74631 100644
--- a//code-library/latest/ug/bash_2_ec2_code_examples.md
+++ b//code-library/latest/ug/bash_2_ec2_code_examples.md
@@ -4752 +4752,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-            --vpc-id "$VPC_ID" 2>&1)
+            --vpc-id "$VPC_ID" \
+            --tag-specifications 'ResourceType=security-group,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=amazon-ecs-service-connect}]' 2>&1)
@@ -4779 +4780 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        aws logs create-log-group --log-group-name "/ecs/service-connect-nginx" 2>&1 | grep -v "ResourceAlreadyExistsException" || {
+        aws logs create-log-group --log-group-name "/ecs/service-connect-nginx" --tags project=doc-smith,tutorial=amazon-ecs-service-connect 2>&1 | grep -v "ResourceAlreadyExistsException" || {
@@ -4789 +4790 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        aws logs create-log-group --log-group-name "/ecs/service-connect-proxy" 2>&1 | grep -v "ResourceAlreadyExistsException" || {
+        aws logs create-log-group --log-group-name "/ecs/service-connect-proxy" --tags project=doc-smith,tutorial=amazon-ecs-service-connect 2>&1 | grep -v "ResourceAlreadyExistsException" || {
@@ -4806 +4807 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-            --tags key=Environment,value=tutorial 2>&1)
+            --tags key=Environment,value=tutorial key=project,value=doc-smith key=tutorial,value=amazon-ecs-service-connect 2>&1)
@@ -4849,0 +4851 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+            aws iam tag-role --role-name ecsTaskExecutionRole --tags Key=project,Value=doc-smith Key=tutorial,Value=amazon-ecs-service-connect
@@ -4880,0 +4883 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+            aws iam tag-role --role-name ecsTaskRole --tags Key=project,Value=doc-smith Key=tutorial,Value=amazon-ecs-service-connect
@@ -4984,0 +4988,8 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+            },
+            {
+                "key": "project",
+                "value": "doc-smith"
+            },
+            {
+                "key": "tutorial",
+                "value": "amazon-ecs-service-connect"
@@ -5415 +5426 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-    VPC_ID=$(aws ec2 create-vpc --cidr-block 10.0.0.0/16 --tag-specifications 'ResourceType=vpc,Tags=[{Key=Name,Value=MyVPC}]' --query 'Vpc.VpcId' --output text)
+    VPC_ID=$(aws ec2 create-vpc --cidr-block 10.0.0.0/16 --tag-specifications 'ResourceType=vpc,Tags=[{Key=Name,Value=MyVPC},{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' --query 'Vpc.VpcId' --output text)
@@ -5446 +5457 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-      --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=Public-Subnet-AZ1}]' \
+      --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=Public-Subnet-AZ1},{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' \
@@ -5462 +5473 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-      --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=Public-Subnet-AZ2}]' \
+      --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=Public-Subnet-AZ2},{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' \
@@ -5479 +5490 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-      --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=Private-Subnet-AZ1}]' \
+      --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=Private-Subnet-AZ1},{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' \
@@ -5495 +5506 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-      --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=Private-Subnet-AZ2}]' \
+      --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=Private-Subnet-AZ2},{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' \
@@ -5509 +5520 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-      --tag-specifications 'ResourceType=internet-gateway,Tags=[{Key=Name,Value=MyIGW}]' \
+      --tag-specifications 'ResourceType=internet-gateway,Tags=[{Key=Name,Value=MyIGW},{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' \
@@ -5528 +5539 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-      --tag-specifications 'ResourceType=route-table,Tags=[{Key=Name,Value=Public-RT}]' \
+      --tag-specifications 'ResourceType=route-table,Tags=[{Key=Name,Value=Public-RT},{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' \
@@ -5566 +5577 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-      --tag-specifications 'ResourceType=route-table,Tags=[{Key=Name,Value=Private-RT}]' \
+      --tag-specifications 'ResourceType=route-table,Tags=[{Key=Name,Value=Private-RT},{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' \
@@ -5598 +5609 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-    EIP_ALLOC=$(aws ec2 allocate-address --domain vpc --query 'AllocationId' --output text)
+    EIP_ALLOC=$(aws ec2 allocate-address --domain vpc --tag-specifications 'ResourceType=elastic-ip,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' --query 'AllocationId' --output text)
@@ -5612 +5623 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-      --tag-specifications 'ResourceType=natgateway,Tags=[{Key=Name,Value=MyNATGateway}]' \
+      --tag-specifications 'ResourceType=natgateway,Tags=[{Key=Name,Value=MyNATGateway},{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' \
@@ -5643,0 +5655 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+      --tag-specifications 'ResourceType=security-group,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' \
@@ -5669,0 +5682 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+      --tag-specifications 'ResourceType=security-group,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' \
@@ -5728 +5741 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-    aws ec2 create-key-pair --key-name "$KEY_NAME" --query 'KeyMaterial' --output text > "${KEY_NAME}.pem" || handle_error "Failed to create key pair"
+    aws ec2 create-key-pair --key-name "$KEY_NAME" --tag-specifications 'ResourceType=key-pair,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' --query 'KeyMaterial' --output text > "${KEY_NAME}.pem" || handle_error "Failed to create key pair"
@@ -5756 +5769 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-      --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=WebServer}]' \
+      --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=WebServer},{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' \
@@ -5786 +5799 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-      --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=DBServer}]' \
+      --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=DBServer},{Key=project,Value=doc-smith},{Key=tutorial,Value=vpc-gs}]' \
@@ -6232,0 +6246,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+        aws iam tag-role --role-name ecsTaskExecutionRole --tags Key=project,Value=doc-smith Key=tutorial,Value=amazon-ecs-fargate-linux
+        
@@ -6247 +6262 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-    CLUSTER_OUTPUT=$(execute_command "aws ecs create-cluster --cluster-name '$CLUSTER_NAME'" "Create ECS cluster")
+    CLUSTER_OUTPUT=$(execute_command "aws ecs create-cluster --cluster-name '$CLUSTER_NAME' --tags key=project,value=doc-smith key=tutorial,value=amazon-ecs-fargate-linux" "Create ECS cluster")
@@ -6335 +6350 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-    SECURITY_GROUP_OUTPUT=$(execute_command "aws ec2 create-security-group --group-name '$SECURITY_GROUP_NAME' --description 'Security group for ECS Fargate tutorial - HTTP access' --vpc-id '$VPC_ID'" "Create security group")
+    SECURITY_GROUP_OUTPUT=$(execute_command "aws ec2 create-security-group --group-name '$SECURITY_GROUP_NAME' --description 'Security group for ECS Fargate tutorial - HTTP access' --vpc-id '$VPC_ID' --tag-specifications 'ResourceType=security-group,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=amazon-ecs-fargate-linux}]'" "Create security group")
@@ -6383 +6398 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-    SERVICE_CMD="aws ecs create-service --cluster '$CLUSTER_NAME' --service-name '$SERVICE_NAME' --task-definition '$TASK_FAMILY' --desired-count 1 --launch-type FARGATE --network-configuration '{\"awsvpcConfiguration\":{\"subnets\":[\"$(echo "$SUBNET_IDS_COMMA" | sed 's/,/","/g')\"],\"securityGroups\":[\"$SECURITY_GROUP_ID\"],\"assignPublicIp\":\"ENABLED\"}}'"
+    SERVICE_CMD="aws ecs create-service --cluster '$CLUSTER_NAME' --service-name '$SERVICE_NAME' --task-definition '$TASK_FAMILY' --desired-count 1 --launch-type FARGATE --network-configuration '{\"awsvpcConfiguration\":{\"subnets\":[\"$(echo "$SUBNET_IDS_COMMA" | sed 's/,/","/g')\"],\"securityGroups\":[\"$SECURITY_GROUP_ID\"],\"assignPublicIp\":\"ENABLED\"}}' --tags key=project,value=doc-smith key=tutorial,value=amazon-ecs-fargate-linux"
@@ -6560,0 +6576,4 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+    # Tags
+    PROJECT_TAG="doc-smith"
+    TUTORIAL_TAG="ecs-ec2"
+    
@@ -6750 +6769 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        CLUSTER_ARN=$(aws ecs create-cluster --cluster-name "$CLUSTER_NAME" --query 'cluster.clusterArn' --output text)
+        CLUSTER_ARN=$(aws ecs create-cluster --cluster-name "$CLUSTER_NAME" --tags key=project,value=$PROJECT_TAG key=tutorial,value=$TUTORIAL_TAG --query 'cluster.clusterArn' --output text)
@@ -6772,0 +6792,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+        
+        aws ec2 create-tags --resources "$KEY_PAIR_NAME" --tags Key=project,Value=$PROJECT_TAG Key=tutorial,Value=$TUTORIAL_TAG 2>>"$LOG_FILE" || log "WARNING: Failed to tag key pair"
@@ -6782,0 +6804 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+            --tag-specifications "ResourceType=security-group,Tags=[{Key=project,Value=$PROJECT_TAG},{Key=tutorial,Value=$TUTORIAL_TAG}]" \
@@ -6854,0 +6877,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+            aws iam tag-role --role-name ecsInstanceRole --tags Key=project,Value=$PROJECT_TAG Key=tutorial,Value=$TUTORIAL_TAG
+            
@@ -6906 +6930 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-            --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=ecs-tutorial-instance}]" \
+            --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=ecs-tutorial-instance},{Key=project,Value=$PROJECT_TAG},{Key=tutorial,Value=$TUTORIAL_TAG}]" \
@@ -6984 +7008,11 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        "networkMode": "bridge"
+        "networkMode": "bridge",
+        "tags": [
+            {
+                "key": "project",
+                "value": "PROJECT_TAG_PLACEHOLDER"
+            },
+            {
+                "key": "tutorial",
+                "value": "TUTORIAL_TAG_PLACEHOLDER"
+            }
+        ]
@@ -6990,0 +7025,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+        sed -i "s|PROJECT_TAG_PLACEHOLDER|$PROJECT_TAG|g" task-definition.json
+        sed -i "s|TUTORIAL_TAG_PLACEHOLDER|$TUTORIAL_TAG|g" task-definition.json
@@ -7024,0 +7061 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+            --tags key=project,value=$PROJECT_TAG key=tutorial,value=$TUTORIAL_TAG \
@@ -7342 +7379,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        --vpc-id "$VPC_ID")
+        --vpc-id "$VPC_ID" \
+        --tag-specifications 'ResourceType=security-group,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=rds-gs}]')
@@ -7374 +7412,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        --subnet-ids "$SUBNET1" "$SUBNET2")
+        --subnet-ids "$SUBNET1" "$SUBNET2" \
+        --tags Key=project,Value=doc-smith Key=tutorial,Value=rds-gs)
@@ -7387 +7426,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        --secret-string '{"username":"adminuser","password":"'"$(openssl rand -base64 16)"'"}')
+        --secret-string '{"username":"adminuser","password":"'"$(openssl rand -base64 16)"'"}' \
+        --tags Key=project,Value=doc-smith Key=tutorial,Value=rds-gs)
@@ -7418 +7458,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        --no-multi-az)
+        --no-multi-az \
+        --tags Key=project,Value=doc-smith Key=tutorial,Value=rds-gs)
@@ -7695 +7735 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        --tag-specifications 'ResourceType=volume,Tags=[{Key=Name,Value=EBSTutorialVolume},{Key=Purpose,Value=Tutorial}]' \
+        --tag-specifications 'ResourceType=volume,Tags=[{Key=Name,Value=EBSTutorialVolume},{Key=Purpose,Value=Tutorial},{Key=project,Value=doc-smith},{Key=tutorial,Value=ebs-gs-volumes}]' \
@@ -7794,0 +7835 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+                    --tag-specifications 'ResourceType=security-group,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=ebs-gs-volumes}]' \
@@ -7820 +7861 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-                    --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=EBSTutorialInstance},{Key=Purpose,Value=Tutorial}]' \
+                    --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=EBSTutorialInstance},{Key=Purpose,Value=Tutorial},{Key=project,Value=doc-smith},{Key=tutorial,Value=ebs-gs-volumes}]' \
@@ -8142 +8182 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-    SERVICE_NETWORK_OUTPUT=$(log_command "aws vpc-lattice create-service-network --name '$SERVICE_NETWORK_NAME' --output json")
+    SERVICE_NETWORK_OUTPUT=$(log_command "aws vpc-lattice create-service-network --name '$SERVICE_NETWORK_NAME' --tags Key=project,Value=doc-smith Key=tutorial,Value=amazon-vpc-lattice-gs --output json")
@@ -8165 +8205 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-    SERVICE_OUTPUT=$(log_command "aws vpc-lattice create-service --name '$SERVICE_NAME' --output json")
+    SERVICE_OUTPUT=$(log_command "aws vpc-lattice create-service --name '$SERVICE_NAME' --tags Key=project,Value=doc-smith Key=tutorial,Value=amazon-vpc-lattice-gs --output json")
@@ -8536 +8576,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        --connection-name "$CONNECTION_NAME")
+        --connection-name "$CONNECTION_NAME" \
+        --tags key=project,value=doc-smith key=tutorial,value=aws-direct-connect-gs)
@@ -8578 +8619,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-    VGW_OUTPUT=$(aws ec2 create-vpn-gateway --type ipsec.1)
+    VGW_OUTPUT=$(aws ec2 create-vpn-gateway --type ipsec.1 \
+        --tag-specifications 'ResourceType=vpn-gateway,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=aws-direct-connect-gs}]')
@@ -9025,0 +9068 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+      --tag-specifications 'ResourceType=instance,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=marketplace-buyer-gs}]' \
@@ -9376,0 +9420 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+        --tags Key=project,Value=doc-smith Key=tutorial,Value=documentdb-gs \
@@ -9465,0 +9510 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+        --tags Key=project,Value=doc-smith Key=tutorial,Value=documentdb-gs \
@@ -9498,0 +9544 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+        --tags Key=project,Value=doc-smith Key=tutorial,Value=documentdb-gs \
@@ -9528,0 +9575 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+        --tags Key=project,Value=doc-smith Key=tutorial,Value=documentdb-gs \
@@ -9913,0 +9961 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+      --tag-specifications 'ResourceType=security-group,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=ec2-basics}]' \
@@ -9982,0 +10031 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+      --tag-specifications 'ResourceType=instance,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=ec2-basics}]' 'ResourceType=volume,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=ec2-basics}]' \
@@ -10064,0 +10114 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+      --tag-specifications 'ResourceType=elastic-ip,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=ec2-basics}]' \
@@ -10303,0 +10353,4 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+    # Tag the bucket
+    aws s3api put-bucket-tagging --bucket "$BUCKET_NAME" \
+        --tagging 'TagSet=[{Key=project,Value=doc-smith},{Key=tutorial,Value=emr-gs}]'
+    
@@ -10412 +10465,3 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        aws ec2 create-key-pair --key-name "$KEY_NAME" --query "KeyMaterial" --output text > "$KEY_NAME_FILE"
+        aws ec2 create-key-pair --key-name "$KEY_NAME" \
+            --tag-specifications 'ResourceType=key-pair,Tags=[{Key=project,Value=doc-smith},{Key=tutorial,Value=emr-gs}]' \
+            --query "KeyMaterial" --output text > "$KEY_NAME_FILE"
@@ -10432,0 +10488 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
+      --tags Key=project,Value=doc-smith Key=tutorial,Value=emr-gs \
@@ -10625 +10681 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-    set -euo pipefail
+    set -uo pipefail
@@ -10738 +10794,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-      --engine valkey 2>&1); then
+      --engine valkey \
+      --tags Key=project,Value=doc-smith Key=tutorial,Value=amazon-elasticache-gs 2>&1); then
@@ -11264 +11321,2 @@ There's more on GitHub. Find the complete example and learn how to set up and ru
-        --encryption-info "{\"EncryptionInTransit\": {\"InCluster\": true, \"ClientBroker\": \"TLS\"}}" 2>&1)
+        --encryption-info "{\"EncryptionInTransit\": {\"InCluster\": true, \"ClientBroker\": \"TLS\"}}" \
+        --tags project=doc-smith,tutorial=amazon-managed-streaming-for-apache-kafka-gs 2>&1)
@@ -11377,0 +11436,3 @@ There's more on GitHub. Find the complete example and learn how to set up and ru