AWS-ECS 클러스터 인스턴스가 Scale-Out될때 작업 재배치 해주는 예시 프로젝트입니다.
- Run
pip install -r requirements.txt - Update
config.yaml - Run
lambda deploy- 배포툴로 python-lambda 라이브러리를 사용하고 있습니다.
- SNS 주제를 만들고 배포된 람다 함수를 구독
- ASG 시작 알람 생성 (웹 콘솔에서 가능)
event.json을 활용하여 로컬에서 테스트할 수 있습니다.lambda invoke -v명령어로 로컬에서 테스트할 수 있습니다.
재배포 하지 않을 서비스를 ,로 구분하여 환경 변수로 주입합니다.
lambda deploy 명령어를 통해 배포할 수 있습니다(실행하면 AWS-Lambda 함수를 만듬).
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Resource": "*",
"Action": [
"sqs:SendMessage",
"sqs:GetQueueUrl",
"sns:Publish"
]
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"ec2:DescribeInstances",
"ec2:DescribeInstanceAttribute",
"ec2:DescribeInstanceStatus",
"ec2:DescribeHosts",
"ecs:ListContainerInstances",
"ecs:DescribeContainerInstances",
"ecs:ListTasks",
"ecs:DescribeTasks",
"ecs:listServices",
"ecs:DescribeServices",
"ecs:updateService"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Resource": "*",
"Action": [
"sns:ListSubscriptions",
"sns:Publish"
]
}
]
}