can i create an elastic agent via an api call
Asked by William Flow:

so i have a script that

creates and ec2 instance

configures it as an elastic agent

creates the AMI

now i want create an elastic agent via that AMI with a API call is this doable via API call? or is there another automated way

Thanks

Bill


Answers:
author: Eduardo Alvarenga
body: Hello [@William Flow](/t5/user/viewprofilepage/user-id/4551025)

Bamboo relies on premade AMIs to launch its Elastic Agents. An EC2 instance that is supposed to be used as an Elastic Agent needs to be launched by Bamboo and cannot be running before that.

Considering your AMI contains all the required applications to launch an Elastic Agent, you just have to add your AMI as a Custom image in Bamboo and launch an Elastic Agent.

Here are some links for you:

* [Creating a custom elastic image](https://confluence.atlassian.com/bamboo/creating-a-custom-elastic-image-289277146.html)
* [Managing your Elastic Image configurations](https://confluence.atlassian.com/bamboo/managing-your-elastic-image-configurations-289277147.html)

Best regards,

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**

comments: author: William Flow
body: Hi Eduardo

Yes I understand that my question is can I fire up an elastic agent via an api call to bamboo? i will know the image id etc

Thanks

Bill


author: Eduardo Alvarenga
body: Hey [@William Flow](/t5/user/viewprofilepage/user-id/4551025)

There is no REST API endpoint that would allow you to control Elastic Agents up/down specifically. Elastic Agents are expected to be started automatically by the [Automatic Elastic Instance Management](https://confluence.atlassian.com/bamboo/configuring-elastic-bamboo-289277120.html#ConfiguringElasticBamboo-Automaticelasticinstancemanagement) feature.

But you can always call the UI through curl, for example, below I'm starting one Elastic Agent from imageId=688129:

```
$ curl -u user:pass 'https://bamboo.mydomain.net/admin/elastic/createElasticInstances.action' -H 'content-type: application/x-www-form-urlencoded' -H 'x-atlassian-token: no-check' -X POST --data-raw 'numAgentsToCreate=1&elasticImageConfigurationId=688129&selectFields=elasticImageConfigurationId&save=Submit'
```

Cheers,

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**


author: William Flow
body: Hi Eduardo

I do have one more question on this in your example you have

```
elasticImageConfigurationId=688129&selectFields=elasticImageConfigurationId&save=Submit'
```

my question is in my instance of Bamboo i dont have the elasticImageConfigurationId I only have elasticImageConfigurationId how do i get the elasticImageConfigurationId ? or do i just use the elasticImageConfigurationId

![ed.png](https://community.atlassian.com/t5/image/serverpage/image-id/248413i9AAA137509592732/image-size/large?v=v2&px=999 "ed.png")


author: Eduardo Alvarenga
body: Hey [@William Flow](/t5/user/viewprofilepage/user-id/4551025)

You can find the list of elastigImageConfigurationId by going to the Bamboo UI:

* **Bamboo Administration** \>\> **Elastic Bambo (Image configuration)** \>\> **Hover the mouse over each instance and take notes of their *configurationId***

For that, you can use the REST API to get a list of the images:

* <https://developer.atlassian.com/server/bamboo/rest/api-group-api/#api-api-latest-elasticconfiguration-get>

For example, the curl below will return all Images Ids and their Names configured on my AWS "*ap-se2*" region:

```
$ curl -s -H "Accept: application/json" -uuser:pass -X GET 'https://bamboo.mydomain.net/rest/api/latest/elasticConfiguration' | jq -j '.[] | select(.region == "ap-se2") | .configurationId, " ", .configurationName, "\n"'
491526 Ubuntu stock image
491534 Windows stock image
688129 ealvarenga-bamboo-agent-linux
9633793 ealvarenga-bamboo-agent-windows
35192833 ealvarenga-bamboo-agent-linux-custom
```

Kind regards,

Eduardo Alvarenga  
Atlassian Support APAC

**--please don't forget to Accept the answer if the reply is helpful--**


author: William Flow
body: Thank you so much! that worked!!\~


Tags: elastic

rest-api