sudo curl -Lo /usr/local/bin/ecs-cli https://amazon-ecs-cli.s3.amazonaws.com/ecs-cli-linux-amd64-latest
sudo chmod +x /usr/local/bin/ecs-cli
Shell
복사
export access=<RootAccessKey>
export secret=<RootSecretKey>
Shell
복사
ecs-cli up --cluster wsi-ecs-cluster --region ap-northeast-2 --empty
Shell
복사
ecs-cli configure --cluster wsi-ecs-cluster --region ap-northeast-2 --default-launch-type FARGATE --config-name wsi-stress-config
Shell
복사
ecs-cli configure profile --access-key $access --secret-key $secret --profile-name stress-profile
Shell
복사
#!/bin/bash
vpc_id=$(aws ec2 describe-vpcs --filters "Name=tag:Name,Values=wsi-vpc" --query "Vpcs[].VpcId[]" --region ap-northeast-2 --output text)
private_a=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=wsi-private-subnet-a" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text)
private_b=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=wsi-private-subnet-b" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text)
ecs_app_sg=$(aws ec2 describe-security-groups --filters "Name=tag:Name,Values=wsi-app-sg" --query "SecurityGroups[].GroupId[]" --region ap-northeast-2 --output text)
target_group_arn=$(aws elbv2 describe-target-groups --names wsi-stress-tg --query "TargetGroups[].TargetGroupArn[]" --region ap-northeast-2 --output text)
Shell
복사
aws ec2 create-security-group --group-name "wsi-app-sg" --description "wsi-app-sg" --vpc-id "$vpc_id"
security_group_id=$(aws ec2 describe-security-groups --filters "Name=tag:Name,Values=wsi-app-sg" --query "SecurityGroups[].GroupId[]" --region ap-northeast-2 --output text)
aws ec2 authorize-security-group-ingress --group-id "$security_group_id" --protocol tcp --port 8080 --cidr 0.0.0.0/0
Shell
복사
cat << EOF > docker-compose-stress.yaml
version: '3'
services:
wsi-stress:
image: 362708816803.dkr.ecr.ap-northeast-2.amazonaws.com/stress:latest
ports:
- "8080:8080"
environment:
- AWS_REGION=ap-northeast-2
- DYNAMODB_TABLE=wsi-table
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/healthcheck"]
interval: 5s
timeout: 2s
retries: 1
logging:
driver: awslogs
options:
awslogs-create-group: "true"
awslogs-group: "wsi-stress"
awslogs-region: "ap-northeast-2"
awslogs-stream-prefix: "wsi-stress"
EOF
Shell
복사
cat << EOF > ecs-params-stress.yaml
version: 1
task_definition:
task_execution_role: ecs-cli-role
ecs_network_mode: awsvpc
task_size:
mem_limit: 0.5GB
cpu_limit: 256
run_params:
network_configuration:
awsvpc_configuration:
subnets:
- "$private_a"
- "$private_b"
security_groups:
- "$ecs_app_sg"
assign_public_ip: DISABLED
EOF
Shell
복사
ecs-cli compose --project-name wsi-taskdef-stress --file docker-compose-stress.yaml --ecs-params ecs-params-stress.yaml --debug service up --region ap-northeast-2 --cluster-config wsi-stress-config --tags Name=wsi-stress --ecs-profile stress-profile --target-groups "targetGroupArn=$target_group_arn,containerName=wsi-stress,containerPort=8080"
Shell
복사
