<p>Use <strong>AWS API</strong> to spin up the instances. There are SDKs (Software Development Kits) for various languages, for example if you're using Python use <a href="https://boto3.amazonaws.com/v1/documentation/api/latest/index.html" rel="nofollow noreferrer">boto3</a> library. SDKs for other platforms are also available: <a href="https://aws.amazon.com/tools/" rel="nofollow noreferrer">Tools to Build on AWS</a>, including the command line tools <a href="https://aws.amazon.com/cli/" rel="nofollow noreferrer">AWS-CLI</a> for use in shell scripts.</p>

<p>With the SDK of choice you'll simply call something like <code>ec2.start_instance(...)</code> to spin up your new EC2. </p>

<p>However I would question whether you really need standalone EC2 instances for your processing? Perhaps ECS Containers, especially <a href="https://aws.amazon.com/fargate/" rel="nofollow noreferrer">Fargate</a>, or even serverless <a href="https://aws.amazon.com/lambda/" rel="nofollow noreferrer">lambda functions</a> triggered from a work queue may be a better choice?</p>

<p>Hope that helps :)</p>

CC BY-SA 4.0
2020-01-06T22:44:34.480Z
Hey thanks! Well the bottleneck of the application is actually the need for different IP addresses. Unless I can get multiple IP's on a single instance somehow, I haven't seen that either.
illcrx
CC BY-SA 4.0
2020-01-06T23:17:45.313Z
@illcrx You can certainly have multiple IPs per EC2 network interface (ENI), on some instances up to 50 IPs per ENI and up to 15 network interfaces per instance. That's 750 IPs per instance - it should be enough ;) On smaller instance it's less but even on the smallest you can have 2 ENIs with 4 IPs each. Have a look here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html#AvailableIpPerENI
MLu
CC BY-SA 4.0
2020-01-06T23:25:36.230Z
are those external IPs?
illcrx
CC BY-SA 4.0
2020-01-06T23:31:33.317Z
@illcrx they are private but you can map a Public IP to each Private IP.
MLu
CC BY-SA 4.0
2020-01-07T13:38:14.233Z
@illcrx what's the purpose for multiple IPs for one instance?  Is it for routing to different containers?  Not sure your use case but maybe you can use a load balancer / reverse proxy to route request based on http requests.
Yan
CC BY-SA 4.0
2020-01-07T19:07:57.727Z
We hit an external API that limits endpoint hits per sec/hr/day and we need to get around that. API is used for single account, were going to manage many accounts, they just didn't design the API for my application use case.
illcrx
CC BY-SA 4.0
2020-01-07T19:24:21.913Z
@illcrx it is possible but not trivial to initiate connections through different ENI and hence get a different public IP for each connection. You would need to update your client code to `bind()` to a specific interface. Or indeed run multiple EC2s or multiple Fargate containers, each with its own public IP.
MLu
CC BY-SA 4.0
2020-01-07T21:54:35.847Z
Still learning this stuff, but was thinking of each instance with it's own IP and we can limit outgoing traffic based on our tests of limits. Not sure past that if we need more IPs. There is likely an IP limit on AWS I'm not sure what it is though.
illcrx
CC BY-SA 4.0
2020-01-07T21:59:02.367Z
@illcrx It may be best to open a new question and exactly describe what are you trying to achieve and what problems you’re facing. I’m afraid this may be an **X-Y Problem** situation. Read this first before continuing: http://xyproblem.info/ and https://en.m.wikipedia.org/wiki/XY_problem
MLu
CC BY-SA 4.0
2020-01-10T15:12:09.857Z
thanks I will! Honestly StackOverflow wants you to ask Y not X, which is why I asked Y. Your are 100% correct though.
illcrx
CC BY-SA 4.0
2020-01-06T01:13:18.627Z
2020-01-06T01:13:18.627Z
MLu
<p>I am developing the architecture of this application and the way we need to scale is not just stateless API requests, but it's a logical split of responsibilities. In other words, we may only be able to work on data 1-5 while we need another instance to work on 6-10. We will need an undefined number of instances and would like a manager to spin up and down EC2 instances as needed. </p>

<p>While scouring the web I am not able to come up with anything good, are there any good articles or is there a term for this? I have found IAC (Infrastrucure as Code) but from what I see that is simply deploying additional services, I don't see anything as IAC spun up from within the application. Is there a term for this? </p>

<amazon-web-services><amazon-ec2>
Spin up an EC2 instance from within the application
illcrx
# Spin up an EC2 instance from within the application

(Asked by: username_0 on 2020-01-06)

I am developing the architecture of this application and the way we need to scale is not just stateless API requests, but it's a logical split of responsibilities. In other words, we may only be able to work on data 1-5 while we need another instance to work on 6-10. We will need an undefined number of instances and would like a manager to spin up and down EC2 instances as needed.

While scouring the web I am not able to come up with anything good, are there any good articles or is there a term for this? I have found IAC (Infrastrucure as Code) but from what I see that is simply deploying additional services, I don't see anything as IAC spun up from within the application. Is there a term for this?

**Tags:** amazon-web-services, amazon-ec2


---

## 1 answers

### Answer by username_1 on 2020-01-06. Score: 3

Use **AWS API** to spin up the instances. There are SDKs (Software Development Kits) for various languages, for example if you're using Python use [boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) library. SDKs for other platforms are also available: [Tools to Build on AWS](https://aws.amazon.com/tools/), including the command line tools [AWS-CLI](https://aws.amazon.com/cli/) for use in shell scripts.

With the SDK of choice you'll simply call something like `ec2.start_instance(...)` to spin up your new EC2.

However I would question whether you really need standalone EC2 instances for your processing? Perhaps ECS Containers, especially [Fargate](https://aws.amazon.com/fargate/), or even serverless [lambda functions](https://aws.amazon.com/lambda/) triggered from a work queue may be a better choice?

Hope that helps :)

> **Comments:**
> **username_0**: Hey thanks! Well the bottleneck of the application is actually the need for different IP addresses. Unless I can get multiple IP's on a single instance somehow, I haven't seen that either.  
> **username_1**: @username_0 You can certainly have multiple IPs per EC2 network interface (ENI), on some instances up to 50 IPs per ENI and up to 15 network interfaces per instance. That's 750 IPs per instance - it should be enough ;) On smaller instance it's less but even on the smallest you can have 2 ENIs with 4 IPs each. Have a look here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html#AvailableIpPerENI  
> **username_0**: are those external IPs?  
> **username_1**: @username_0 they are private but you can map a Public IP to each Private IP.  
> **username_2**: @username_0 what's the purpose for multiple IPs for one instance?  Is it for routing to different containers?  Not sure your use case but maybe you can use a load balancer / reverse proxy to route request based on http requests.  
> **username_0**: We hit an external API that limits endpoint hits per sec/hr/day and we need to get around that. API is used for single account, were going to manage many accounts, they just didn't design the API for my application use case.  
> **username_1**: @username_0 it is possible but not trivial to initiate connections through different ENI and hence get a different public IP for each connection. You would need to update your client code to `bind()` to a specific interface. Or indeed run multiple EC2s or multiple Fargate containers, each with its own public IP.  
> **username_0**: Still learning this stuff, but was thinking of each instance with it's own IP and we can limit outgoing traffic based on our tests of limits. Not sure past that if we need more IPs. There is likely an IP limit on AWS I'm not sure what it is though.  
> **username_1**: @username_0 It may be best to open a new question and exactly describe what are you trying to achieve and what problems you’re facing. I’m afraid this may be an **X-Y Problem** situation. Read this first before continuing: http://xyproblem.info/ and https://en.m.wikipedia.org/wiki/XY_problem  
> **username_0**: thanks I will! Honestly StackOverflow wants you to ask Y not X, which is why I asked Y. Your are 100% correct though.  

---

