Skip to content

Instantly share code, notes, and snippets.

@philschmid
Last active October 28, 2019 14:49
Show Gist options
  • Save philschmid/0122184b25b27d43597c27a1825f29e1 to your computer and use it in GitHub Desktop.
Save philschmid/0122184b25b27d43597c27a1825f29e1 to your computer and use it in GitHub Desktop.

Idea

  1. set Var for functionality -> get CF output stack (AMI-ID, SQS_QUEUE, S3_bucket)
  2. get messages in queue
  3. evalute ec2 instances (atm message_count / 5 )
  4. check how many instances are running, based on filter (module)
  5. calculate required instance ( +2 means -> has to start to more, -2 means stop 2 )
  6. if less instances are running start instances
    6.1 start instance
    a. set min & max count to difference of actual running instances and evaluted_number
    b. wait until running
    c. set tag for instance (module)
    6.2 if more instances are running stop instances
    a. get all instances and filter based on tags
    b. stop difference from actual running instances and evaluted_number
  7. finish

Problems

import boto3
def get_cf_outputs(stack_name):
cf_conn = boto3.client('cloudformation', region_name='eu-central-1')
stack = cf_conn.describe_stacks(StackName=stack_name)
print(stack['Stacks'][0]['Outputs'][0]['OutputValue'])
# check with index you need couldn´t test it
return stack['Stacks'][0]['Outputs'][0]['OutputValue']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment