-
-
Save myouju/e81597f72a100d57cb1f to your computer and use it in GitHub Desktop.
cloudwatchのアラームからecsのインスタンス数を増やすaws lambdaスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('Loading event'); | |
var aws = require('aws-sdk'); | |
exports.handler = function(event, context) { | |
var cluster = 'maeno-test' | |
var ecsService = 'test-service'; | |
var ecsRegion = 'ap-northeast-1'; | |
var maxCount = 3; | |
var ecs = new aws.ECS({region: ecsRegion}); | |
ecs.describeServices({services:[ecsService],cluster:cluster}, function(err, data) { | |
if (err) { | |
console.log(err, err.stack); | |
} else { | |
var desiredCount = data.services[0].desiredCount; | |
if (desiredCount < maxCount) { | |
desiredCount++; | |
var params = { | |
cluster: cluster, | |
service: ecsService, | |
desiredCount: desiredCount | |
}; | |
ecs.updateService(params, function(err, data) { | |
if (err) { | |
console.log(err, err.stack); | |
} else { | |
console.log(data); | |
context.succeed(); | |
} | |
}); | |
} else { | |
console.log('Service count is already max.'); | |
context.fail(); | |
} | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment