Amazon EventBrdige ์Šค์ผ€์ค„๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Amazon ECS ํด๋Ÿฌ์Šคํ„ฐ๋กœ ์šด์šฉ๋˜๋Š” ์„œ๋น„์Šค์™€ EC2 ์ธ์Šคํ„ด์Šค์˜ ๊ทœ๋ชจ๋ฅผ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, AWS Instance Scheduler ์†”๋ฃจ์…˜๋กœ ์Šคํ…Œ์ด์ง•์ด๋‚˜ ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ์— ๋Œ€ํ•œ EC2 ์ธ์Šคํ„ด์Šค๋“ค์„ ํ‰์ผ ์—…๋ฌด ์‹œ๊ฐ„์—๋งŒ ์‹คํ–‰๋˜๋„๋ก ์‹œ์ž‘, ์ข…๋ฃŒ ์Šค์ผ€์ค„๋ง์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. Amazon ECS์˜ ์˜ˆ์•ฝ๋œ ์ž‘์—…์œผ๋กœ๋Š” ํŠน์ • ํƒœ์Šคํฌ๋ฅผ ์ผ์ • ์‹œ๊ฐ„์— ์‹œ์ž‘ํ•  ์ˆœ ์žˆ์œผ๋‚˜ ์ข…๋ฃŒํ•  ์ˆœ ์—†๋‹ค. ์ด๋Ÿฌํ•œ ๊ฒฝ์šฐ Application Auto Scaling์„ ํ™œ์šฉํ•ด์•ผํ•˜๊ณ  AWS CLI๋ฅผ ๋Œ€์‹ ํ•˜์—ฌ ์ผ์ • ๊ธฐ๋ฐ˜์œผ๋กœ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ๋ฐฉ๋ฒ•์ด ๋ฐ”๋กœ Amazon EventBridge ์Šค์ผ€์ค„๋Ÿฌ ์ด๋‹ค.

์˜คํ† ์Šค์ผ€์ผ๋ง ๊ทธ๋ฃน์˜ ์˜ˆ์•ฝ๋œ ์ž‘์—…

Amazon EventBridge ์Šค์ผ€์ค„๋Ÿฌ๋กœ ์˜คํ† ์Šค์ผ€์ผ๋ง ๊ทธ๋ฃน์˜ EC2 ์ธ์Šคํ„ด์Šค ์šฉ๋Ÿ‰์„ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ทธ์ „์— ์˜คํ† ์Šค์ผ€์ผ๋ง ๊ทธ๋ฃน์— ๋Œ€ํ•œ ์ฝ˜์†”์—์„œ ์ž์ฒด์ ์œผ๋กœ ์ œ๊ณตํ•˜๋Š” ์˜ˆ์•ฝ๋œ ์ž‘์—…์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์ž. EC2 ์šฉ๋Ÿ‰ ๊ณต๊ธ‰์ž๋กœ ์‚ฌ์šฉ์ค‘์ธ ์˜คํ† ์Šค์ผ€์ผ๋ง ๊ทธ๋ฃน์˜ ์ž๋™ ํ™•์žฅ ๊ธฐ๋Šฅ์œผ๋กœ ์˜ˆ์•ฝ๋œ ์ž‘์—…์„ ์ •์˜ํ•˜๋ฉด ํฌ๋ก  ํ‘œํ˜„์‹์— ์˜ํ•ด ํ‰์ผ ์—…๋ฌด ์‹œ๊ฐ„์„ ์œ„ํ•œ ์„œ๋น„์Šค ํ™˜๊ฒฝ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. ์Šคํ…Œ์ด์ง• ๋˜๋Š” ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ์€ ๊ฐœ๋ฐœ์ž ๋˜๋Š” ํ…Œ์ŠคํŠธ ์—”์ง€๋‹ˆ์–ด๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š์€ ์‹œ๊ฐ„์—๋Š” ์ข…๋ฃŒํ•˜์—ฌ ์ž‰์—ฌ ์‹œ๊ฐ„์— ๋Œ€ํ•œ ์š”๊ธˆ์„ ์ค„์—ฌ๊ฐˆ ์ˆ˜ ์žˆ๋‹ค.

๋‹ค๋งŒ, ์˜คํ† ์Šค์ผ€์ผ๋ง ๊ทธ๋ฃน ์ฝ˜์†”์—์„œ ์ œ๊ณตํ•˜๋Š” ์˜ˆ์•ฝ๋œ ์ž‘์—…์œผ๋กœ ๋งŒ๋“ค์–ด์ง€๋Š” ์Šค์ผ€์ค„์€ ์ผ์‹œ์ ์œผ๋กœ ๋น„ํ™œ์„ฑํ™”ํ•˜์ง€ ๋ชปํ•˜๋Š” ๋‹จ์ ์ด ์žˆ๊ณ , ECS ํด๋Ÿฌ์Šคํ„ฐ์—์„œ EC2 ์ธ์Šคํ„ด์Šค์— ์‹คํ–‰๋˜๊ณ  ์žˆ๋Š” ์„œ๋น„์Šค๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ecs-managed-draining-termination-hook ์ˆ˜๋ช… ์ฃผ๊ธฐ ํ›„ํฌ์˜ ์ œํ•œ ์‹œ๊ฐ„(๊ธฐ๋ณธ๊ฐ’ 3,600์ดˆ)์œผ๋กœ ์ธํ•ด ์˜คํ† ์Šค์ผ€์ผ๋ง ๊ทธ๋ฃน์˜ ์˜ˆ์•ฝ๋œ ์ž‘์—…์— ์˜ํ•ด ์ข…๋ฃŒ๋˜์ง€ ์•Š๊ณ  ๊ธฐ๋‹ค๋ฆด ์ˆ˜ ์žˆ๋‹ค.

๐Ÿ”ฅ TaskFailedToStart: EMPTY CAPACITY PROVIDER

์˜คํ† ์Šค์ผ€์ผ๋ง ๊ทธ๋ฃน์˜ ์˜ˆ์•ฝ๋œ ์ž‘์—…์œผ๋กœ EC2 ์ธ์Šคํ„ด์Šค๊ฐ€ ๊ฐ•์ œ๋กœ ์ข…๋ฃŒ๋œ ๊ฒฝ์šฐ ์„œ๋น„์Šค๋กœ ์‹คํ–‰๋˜๋Š” ํƒœ์Šคํฌ๋Š” ์ƒˆ๋กญ๊ฒŒ ๋งŒ๋“ค์–ด์ง€๋ฉฐ ์ง€์†์ ์œผ๋กœ ํ”„๋กœ๋น„์ €๋‹์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

Amazon EventBridge ์Šค์ผ€์ค„๋Ÿฌ๋กœ ์˜คํ† ์Šค์ผ€์ผ๋ง ๊ทธ๋ฃน ์กฐ์ •

Amazon EventBridge ์Šค์ผ€์ค„๋Ÿฌ์—์„œ EC2 Auto Scaling ์„œ๋น„์Šค์˜ SetDesiredCapacity ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์˜คํ† ์Šค์ผ€์ผ๋ง ๊ทธ๋ฃน์— ๋Œ€ํ•ด ์›ํ•˜๋Š” ์šฉ๋Ÿ‰์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋งŒ์•ฝ, EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ์ข…๋ฃŒํ•œ ์ƒํƒœ๋กœ ์œ ์ง€ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์›ํ•˜๋Š” ์šฉ๋Ÿ‰์ด 0 ์ด ๋˜๋„๋ก ํŽ˜์ด๋กœ๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ๋œ๋‹ค.

{
  "AutoScalingGroupName": "mambo-ecs-cluster-asg",
  "DesiredCapacity": 0
}

Amazon EventBridge ์Šค์ผ€์ค„๋Ÿฌ์— ๋Œ€ํ•œ ์ด๋ฒคํŠธ ๋กœ๊ทธ

๋งŒ์•ฝ, ์•ž์„  Amazon EventBridge ์Šค์ผ€์ค„๋Ÿฌ์— ์˜ํ•ด EC2 Auto Scaling ์„œ๋น„์Šค๋กœ ์˜คํ† ์Šค์ผ€์ผ๋ง ๊ทธ๋ฃน์˜ ์šฉ๋Ÿ‰์„ ์ค„์ด๊ณ ์ž ํ•˜๋Š”๋ฐ ์ด๋ฒคํŠธ๊ฐ€ ๋™์ž‘ํ•˜๋Š”์ง€๋ฅผ ์•Œ๊ธฐ ์–ด๋ ค์šด ๊ฒฝ์šฐ CloudTrail์˜ ์ด๋ฒคํŠธ ๊ธฐ๋ก์—์„œ ํ™•์ธํ•ด์•ผ ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์•„๋ž˜์™€ ๊ฐ™์ด ์˜คํ† ์Šค์ผ€์ผ๋ง ๊ทธ๋ฃน์— ๋Œ€ํ•œ ์ด๋ฒคํŠธ ๋Œ€์ƒ์„ ECS ํด๋Ÿฌ์Šคํ„ฐ ์ด๋ฆ„์œผ๋กœ ์ž˜๋ชป ์ง€์ •ํ•ด์„œ ValidationException ์ด ๋ฐœ์ƒํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "xxxxx:xxxxx",
        "arn": "arn:aws:sts::xxxxx:assumed-role/ecsEventsRole/xxxxx",
        "accountId": "xxxxx",
        "accessKeyId": "xxxxx",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "xxxxx",
                "arn": "arn:aws:iam::xxxxx:role/ecsEventsRole",
                "accountId": "xxxxx",
                "userName": "ecsEventsRole"
            },
            "webIdFederationData": {},
            "attributes": {
                "creationDate": "2024-11-15T15:57:59Z",
                "mfaAuthenticated": "false"
            }
        }
    },
    "eventTime": "2024-11-15T15:57:59Z",
    "eventSource": "autoscaling.amazonaws.com",
    "eventName": "SetDesiredCapacity",
    "awsRegion": "ap-northeast-2",
    "sourceIPAddress": "3.34.11.70",
    "userAgent": "AmazonEventBridgeScheduler aws-sdk-java/2.28.29 md/io#async md/http#NettyNio md/internal ua/2.0 os/Linux#5.10.226-214.880.amzn2.x86_64 lang/java#17.0.13 md/OpenJDK_64-Bit_Server_VM#17.0.13+11-LTS md/vendor#Amazon.com_Inc. md/en_US md/kotlin/1.6.21-release-334(1.6.21) exec-env/AWS_ECS_FARGATE cfg/retry-mode#legacy cfg/auth-source#stat",
    "errorCode": "ValidationException",
    "errorMessage": "AutoScalingGroup name not found - null",
    "requestParameters": {
        "autoScalingGroupName": "mambo-ecs-cluster",
        "desiredCapacity": 1
    },
    "responseElements": null,
    "requestID": "1d4e8568-2303-48ee-a6fa-2c3ca5be257d",
    "eventID": "99a3097c-96ce-43dd-8c97-1aa0985c701b",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "recipientAccountId": "xxxx",
    "eventCategory": "Management",
    "tlsDetails": {
        "tlsVersion": "TLSv1.3",
        "cipherSuite": "TLS_AES_128_GCM_SHA256",
        "clientProvidedHostHeader": "autoscaling.ap-northeast-2.amazonaws.com"
    }
}

์•„๋ฌด๋ž˜๋„ Amazon ECS ์—์„œ Amazon ECR์— ๋Œ€ํ•œ ๋งํฌ๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ Amazon EventBridge ์Šค์ผ€์ค„๋Ÿฌ ์ฝ˜์†”์—์„œ๋„ Amazon CloudTrail ์— ๋Œ€ํ•œ ๋งํฌ๋ฅผ ์ œ๊ณตํ•ด์ฃผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Amazon EventBridge ์Šค์ผ€์ค„๋Ÿฌ๋กœ ์„œ๋น„์Šค ๊ทœ๋ชจ ์กฐ์ •

{
  "Cluster": "mambo-ecs-cluster",
  "Service": "app-service",
  "DesiredCount": 0
}

EC2 ์ธ์Šคํ„ด์Šค์˜ ์‹œ์ž‘๊ณผ ์ข…๋ฃŒ์— ๋Œ€ํ•œ ์ผ์ •์„ ๊ตฌ์„ฑํ–ˆ๋‹ค๋ฉด ์ด์ œ Amazon EventBridge ์Šค์ผ€์ค„๋Ÿฌ์—์„œ Amazon ECS ์„œ๋น„์Šค ๋Œ€์ƒ์œผ๋กœ UpdateService๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ํŠน์ • ํด๋Ÿฌ์Šคํ„ฐ์— ์กด์žฌํ•˜๋Š” ์„œ๋น„์Šค์— ๋Œ€ํ•ด DesiredCount๋ฅผ ์„ค์ •ํ•˜์—ฌ ์„œ๋น„์Šค์— ๋Œ€ํ•œ ๊ทœ๋ชจ๋ฅผ ์กฐ์ •ํ•ด๋ณด๋„๋ก ํ•˜์ž.

Application Auto Scaling ๋กœ ์„œ๋น„์Šค ๊ทœ๋ชจ ์กฐ์ •

Amazon ECS ์„œ๋น„์Šค๊ฐ€ ์•„๋‹Œ Application Auto Scaling ์„œ๋น„์Šค์˜ register-scalable-target๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๋™์ผํ•œ ๋™์ž‘์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

{
  "ResourceId": "service/mambo-ecs-cluster/app-service",
  "ScalableDimension": "ecs:service:DesiredCount",
  "ServiceNamespace": "ecs",
  "MinCapacity": 0,
  "MaxCapacity": 0
}

Amazon EventBridge Scheduler IAM ์—ญํ• 

Amazon ECS EventBridge IAM ์—ญํ• ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ Amazon EventBridge ์Šค์ผ€์ค„๋Ÿฌ์—์„œ Amazon ECS ์™€ EC2 Auto Scaling ์— ๋Œ€ํ•œ ๊ถŒํ•œ์„ ๊ฐ€์ง€๋Š” IAM ์—ญํ• ์ธ ecsEventsRole ์„ ๊ตฌ์„ฑํ•œ ์˜ˆ์‹œ์ด๋‹ค. ์ผ์ •์— ๋Œ€ํ•œ ์ด๋ฒคํŠธ ๊ธฐ๋ก์—์„œ ๊ถŒํ•œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค๋ฉด IAM ์—ญํ• ์˜ ์‹ ๋ขฐ ๊ด€๊ณ„์™€ ์—ฐ๊ฒฐ๋œ ์ •์ฑ…์„ ์‚ดํŽด๋ณด๋„๋ก ํ•˜์ž.

์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ์—”ํ‹ฐํ‹ฐ
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "Service": [
                    "events.amazonaws.com",
                    "autoscaling.amazonaws.com",
                    "scheduler.amazonaws.com"
                ]
            },
            "Action": "sts:AssumeRole"
        }
    ]
}
์—ฐ๊ฒฐ๋œ ์ •์ฑ…
  • AmazonECS_FullAccess
  • AmazonEventBridgeSchedulerFullAccess
  • AutoScalingFullAccess

์ฐธ๊ณ  ๋งํฌ