[Amazon EventBridge] AWS EventBridge Scheduler๋ฅผ ์ด์šฉํ•˜์—ฌ ์†์‰ฝ๊ฒŒ EC2, RDS ์ค‘์ง€ ๋ฐ ์žฌ์‹œ์ž‘ํ•˜๊ธฐ

2023. 10. 1. 20:13ใ†AWS

โ˜„๏ธ ๊ฐœ์š”

To-Be Architecture

์ˆ˜ํ–‰ ์ค‘์ธ ๊ตฌ์ถ• ํ”„๋กœ์ ํŠธ์—์„œ ๋น„์šฉ ์ ˆ๊ฐ์„ ๋ชฉ์ ์œผ๋กœ ๊ธธ์—ˆ๋˜ ์ถ”์„ ์—ฐํœด ๊ฐ„ EC2, RDS๋ฅผ ์ค‘์ง€ํ•˜๊ธฐ๋กœ ํ–ˆ๋‹ค. 

์ผ๋ถ€ ์‹œ์Šคํ…œ์„ ์ œ์™ธํ•˜๊ณ  EC2์™€ RDS๋ฅผ ์ค‘์ง€ ์ƒํƒœ๋กœ ๋ณ€๊ฒฝํ•ด์•ผ ํ–ˆ๋Š”๋ฐ ์ˆ˜๋™์œผ๋กœ ํ•˜๋‚˜ํ•˜๋‚˜ ์ž‘์—…ํ•˜๊ธฐ์—๋Š” ๋Œ€์ˆ˜๊ฐ€ ๋งŽ์•„ ์ผ๊ด„๋กœ ์ ์šฉ์‹œํ‚ค๊ธฐ ์œ„ํ•ด  EventBridge Scheduler๋ฅผ ์ด์šฉํ•˜์˜€๋‹ค.

 


 

1. IAM Role ์ƒ์„ฑ

Eventbridge Scheduler์— ์ ์šฉํ•  IAM Role์„ ์ƒ์„ฑํ•œ๋‹ค. EC2, RDS ์ธ์Šคํ„ด์Šค๋ฅผ ์ค‘์ง€/์‹œ์ž‘ํ•˜๋Š” ๊ถŒํ•œ์„ ๊ฐ€์ง„๋‹ค.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ec2:StartInstances",
                "rds:StopDBInstance",
                "ec2:StopInstances",
                "rds:StartDBInstance"
            ],
            "Resource": "*"
        }
    ]
}

Trust Relationship์€ ์•„๋ž˜ ์ฐธ์กฐ.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "scheduler.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

2. EventBridge Schedule ์ƒ์„ฑ

์ผํšŒ์„ฑ ์ด๋ฒคํŠธ์ด๊ธฐ ๋•Œ๋ฌธ์— One-time schedule์„ ์ด์šฉํ•˜์—ฌ ์Šค์ผ€์ค„์„ ์ƒ์„ฑํ•œ๋‹ค.

EventBridge๊ฐ€ ์ •ํ•ด์ง„ ์‹œ๊ฐ„์— ํ˜ธ์ถœํ•  API๋ฅผ ์„ ํƒํ•œ๋‹ค. EC2์˜ StopInstances API๋ฅผ ์„ ํƒํ•œ๋‹ค. RDS์˜ ๊ฒฝ์šฐ, StopDBInstance API๋ฅผ ์„ ํƒํ•œ๋‹ค.

target์„ ์„ ํƒํ•˜๋ฉด ๋œจ๋Š” input window์— ์ค‘์ง€์‹œ์ผœ์•ผ ํ•˜๋Š” ์ธ์Šคํ„ด์Šค ๋ชฉ๋ก์„ ์œ„์™€ ๊ฐ™์ด ์ž…๋ ฅํ•œ๋‹ค. RDS์˜ ๊ฒฝ์šฐ์—๋Š” ์ธ์Šคํ„ด์Šค ๋ชฉ๋ก์œผ๋กœ ์ž…๋ ฅ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜์—ฌ RDS ๋Œ€์ˆ˜๋งŒํผ EventBridge Scheduler๋ฅผ ๋งŒ๋“ค์–ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.๐Ÿคฆ‍โ™€๏ธ

1์—์„œ ์ƒ์„ฑํ•œ IAM Role์„ ์—ฐ๊ฒฐํ•œ๋‹ค.

 

 

์›ํ•˜๋Š” ์‹œ๊ฐ„์— EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ์ผ๊ด„๋กœ ์ค‘์ง€ํ•˜๋Š” ์Šค์ผ€์ค„๋Ÿฌ ๋งŒ๋“ค๊ธฐ ์„ฑ๊ณต ๐Ÿ˜‡


๐Ÿ’ก ๋Š๋‚€ ์ 

RDS ์ธ์Šคํ„ด์Šค๋ฅผ StopDBInstance API/StartDBInstance API๊ฐ€ ์ธ์Šคํ„ด์Šค ๋ชฉ๋ก์ด ์•„๋‹Œ ๋‹จ์ผ ์ธ์Šคํ„ด์Šค๋งŒ ์ž…๋ ฅ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. ๋”ฐ๋ผ์„œ RDS ์ธ์Šคํ„ด์Šค ๋Œ€์ˆ˜๋งˆ๋‹ค Scheduler๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ–ˆ์ง€๋งŒ, ์ƒˆ๋ฒฝ์— ์ผ์–ด๋‚˜์„œ ์ˆ˜๋™์œผ๋กœ ์ž‘์—…ํ•˜๊ณ  ์‹ถ์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฏธ๋ฆฌ ์Šค์ผ€์ค„๋Ÿฌ๋ฅผ ๋งŒ๋“ค์–ด ์ผ์ฐ ๋งค ๋งž๊ธฐ๋ฅผ ์„ ํƒํ–ˆ๋‹ค..๐Ÿ˜‚ ์›ํ•˜๋Š” ์‹œ๊ฐ„์— RDS ์ธ์Šคํ„ด์Šค๋ฅผ ์ผ๊ด„๋กœ ์ค‘์ง€์‹œํ‚ค๋Š” ์ข‹์€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค๋ฉด ์•Œ๊ณ  ์‹ถ๋‹ค..!

 

์ถ”๊ฐ€๋กœ, Instance Scheduler on AWS๋ฅผ ์ด์šฉํ•˜์—ฌ ์ ์šฉํ•ด๋†“์€ daily ์Šค์ผ€์ค„๋Ÿฌ๋ฅผ ์ถ”์„ ์—ฐํœด ๊ธฐ๊ฐ„ ๋™์•ˆ์€ ๋„๊ธฐ ์œ„ํ•ด EC2, RDS์— ์ ์šฉํ•ด ๋†“์€ Schedule ํƒœ๊ทธ๋Š” ์ž ์‹œ ๋ณ€๊ฒฝํ•ด ๋†“์•˜๋‹ค. ๋‹ค๋ฅธ ์Šค์ผ€์ค„๋Ÿฌ๋ฅผ ๊ธฐ์กด์— ์ ์šฉํ•ด ๋†“์€ ๊ฒฝ์šฐ๋Š” ํ•ด๋‹น ์Šค์ผ€์ค„๋Ÿฌ๊ฐ€ ์ˆ˜ํ–‰๋˜์ง€ ์•Š๋„๋ก ์ฃผ์˜ํ•˜์ž. Instance Scheduler on AWS๋ฅผ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜ ํฌ์ŠคํŒ… ์ฐธ๊ณ .

 

Multi-account ๊ตฌ์กฐ์—์„œ AWS ๋ฆฌ์†Œ์Šค(EC2, RDS) ์ž๋™ ์‹œ์ž‘-์ค‘์ง€ ์Šค์ผ€์ค„๋Ÿฌ ๊ตฌ์„ฑํ•˜๊ธฐ : Instance Scheduler on AWS

EventBridge ๋˜๋Š” Lambda ํ•จ์ˆ˜ ๊ตฌ์„ฑ์„ ํ†ตํ•ด ์Šค์ผ€์ค„๋Ÿฌ๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ• ์™ธ์— AWS์—์„œ ์ œ๊ณตํ•˜๋Š” ๋‘ ๊ฐ€์ง€ ์†”๋ฃจ์…˜์ด ์žˆ๋‹ค. AWS System Manager > Quick Setup > Resource Scheduler Instance Scheduler on AWS 0. ์Šค์ผ€์ค„๋Ÿฌ ์†”๋ฃจ์…˜

hyeon-joo.tistory.com