1

Currently I have windows ec2 instance running my selenium tests. I invoke the tests from Jenkins which runs the test in the configured node.

Sometimes the problem might be that the ec2 instance might be turned off.

How do I integrate starting the launching of the aws windows machine in my scripts.

1

Since you are running selenium, I am guessing you are using python for your scripts. If that is the case then boto3 is the way to go. https://boto3.readthedocs.io/en/latest/guide/ec2-example-managing-instances.html

With this you can easily check the current state and start it if it is off. You will need to set up aws sdk keys http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html
So something like this might work, you might need to make some changes:

import boto3
ec2 = boto3.resource('ec2')
instance = ec2.Instance('instance_id')

if instance.state['Name'] != u'running':
  try:
      ec2.start_instances(InstanceIds=[instance_id], DryRun=True)
  except ClientError as e:
      if 'DryRunOperation' not in str(e):
          raise
  try:
      response = ec2.start_instances(InstanceIds=[instance_id], DryRun=False)
      print(response)
  except ClientError as e:
      print(e)   
  • Is there any java equivalent for this solution? – Swastik Dec 3 '17 at 20:15
0

Probably there are jenkins plugins that are capable to doing that. Anyway, You can always create simple script that will use AWS REST API. Bellow You will find AWS API reference.

Amazon EC2 API Reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.