Worldskills 2024
Menu
Deployment
EC2
ECR
EKS
Serverless
Other
Utility
Best Practices
Home
CLI
Linux
nginx
userdata
0 Clicks
VPC ID:
Public Subnets:
Security Groups
Copy
aws ec2 create-security-group --group-name ec2-sg --description "attached to ec2" --vpc-id aws ec2 create-security-group --group-name rds-sg --description "attached to rds" --vpc-id aws ec2 create-security-group --group-name redis-sg --description "attached to redis" --vpc-id aws ec2 create-security-group --group-name efs-sg --description "attached to efs" --vpc-id aws ec2 create-security-group --group-name alb-sg --description "attached to alb" --vpc-id
EC2
Copy
$sgId = aws ec2 describe-security-groups --filters ` "Name=group-name,Values=ec2-sg" --query "SecurityGroups[*].GroupId" --output text aws ec2 create-key-pair ` --key-name bastionKey ` --query 'KeyMaterial' ` --output text | Out-File -FilePath bastionKey.ppk -Encoding ascii aws ec2 run-instances --image-id ami-0de02246788e4a354 ` --count 1 ` --instance-type t2.micro ` --key-name bastionKey ` --security-group-ids $sgId ` --subnet-id ` --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=Server01}]" "ResourceType=volume,Tags=[{Key=Name,Value=Server01}]"
ALB
Copy
$albSgId = aws ec2 describe-security-groups --filters ` "Name=group-name,Values=ec2-sg" --query "SecurityGroups[*].GroupId" --output text aws elbv2 create-load-balancer --name server-alb ` --subnets --security-groups $albSgId ` --ip-address-type ipv4 aws elbv2 create-target-group --name server01 --protocol HTTP --port 80 ` --vpc-id --ip-address-type ipv4 --target-type instance $albArn = aws elbv2 describe-load-balancers ` --query "LoadBalancers[?LoadBalancerName=='server-alb'].LoadBalancerArn" ` --output text $tgArn = aws elbv2 describe-target-groups ` --query "TargetGroups[?TargetGroupName=='server01'].TargetGroupArn" ` --output text aws elbv2 create-listener --load-balancer-arn $albArn ` --protocol HTTP --port 80 ` --default-actions Type=forward,TargetGroupArn=$tgArn
Auto scaling group
Copy
aws ec2 create-launch-template ` --launch-template-name MyLaunchTemplate ` --version-description "Initial version" ` --launch-template-data '{ "imageId": "ami-0de02246788e4a354", "instanceType": "t2.micro", "keyName": "bastionKey", "securityGroupIds": ["$sgId"], "tagSpecifications": [ { "resourceType": "instance", "tags": [ { "key": "Name", "value": "Server01" } ] }, { "resourceType": "volume", "tags": [ { "key": "Name", "value": "Server01" } ] } ], "iamInstanceProfile": { "name": "EC2_SSM_Role" }, }'