Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7174753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:07:28+00:00 2026-05-28T16:07:28+00:00

How do i start and stop an amazon EC2 instance programmatically using aws-sdk in

  • 0

How do i start and stop an amazon EC2 instance programmatically using aws-sdk in java?

Any helps are greatly appreciated as I have spent a day while trying to sort this out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:07:29+00:00Added an answer on May 28, 2026 at 4:07 pm

    I’ve recently implemented this functionality within the Bamboo AWS Plugin; it’s Open Source and the code is available on Bitbucket, you can find a complete example how to start/stop/reboot an instance within EC2Task.java (should be a separate class actually, alas …).

    Fortunately this is not complicated at all, for example, an instance can be started like so:

    private String startInstance(final String instanceId, AmazonEC2 ec2, final BuildLogger buildLogger)
            throws AmazonServiceException, AmazonClientException, InterruptedException
    {
        StartInstancesRequest startRequest = new StartInstancesRequest().withInstanceIds(instanceId);
        StartInstancesResult startResult = ec2.startInstances(startRequest);
        List<InstanceStateChange> stateChangeList = startResult.getStartingInstances();
        buildLogger.addBuildLogEntry("Starting instance '" + instanceId + "':");
    
        // Wait for the instance to be started
        return waitForTransitionCompletion(stateChangeList, "running", ec2, instanceId, buildLogger); }
    

    BuildLogger is Bamboo specific and waitForTransitionCompletion() is an implementation specific helper to report back on the process/result. The AmazonEC2 ec2 parameter passes the reference to an AmazonEC2Client object by means of the AmazonEC2 interface, which defines all relevant methods (amongst many others), specifically:

    • StartInstances()
    • StopInstances()
    • RebootInstances()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to start / stop an Amazon EC2 instance from Google
Which class/method to use to start/stop a List of amazon EC2 instances with java
I have been trying to make an init script using start-stop-daemon. I am stuck
I have a very simple Activity to record audio using MediaRecorder . Basic start/stop
how do start/stop services using net stop command in c# for example Dim pstart
I have a list of timesheet entries that show a start and stop time.
I have an activity with two buttons, start and stop. If the user press
Pseudo-situation: have a class (let's say BackgroundMagic ), and it has Start() and Stop()
How can we start/stop a Windows Service from Java? For example, I would like
How to control (start / stop encoding) Flash Media Encoder 3.5 using ActionScript 3

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.