Reputation: 5204
How do I create an instance with a chosen name from an instance template on aws.
Previously when I was on google cloud, first I created an instance template for example it was called node-template
.
To create servers, I would use the following command in the gcloud cli,
gcloud instances create node-1 --source-instance-template=node-template
gcloud instances create node-2 --source-instance-template=node-template
gcloud instances create node-3 --source-instance-template=node-template
....
Is something similar possible with aws?
I basically need to create multiple instances with similar specs and be able to start them, SSH into them and stop them everyday.
Upvotes: 0
Views: 1730
Reputation: 270154
The AWS CLI command aws ec2 run-instances
can be used to launch Amazon EC2 instances. See: run-instances — AWS CLI Command Reference
The command allows all parameters to be specified in JSON, and this can come from disk:
aws ec2 run-instances --cli-input-json file://my-parameters.json
See: Loading AWS CLI parameters from a file - AWS Command Line Interface
Alternatively, you might want to Launch an instance from a launch template - Amazon Elastic Compute Cloud, which is a pre-defined definition of an Amazon EC2 instance that is stored in your AWS Account. You can then reference this launch template when launch an instance:
aws ec2 run-instances --launch-template LaunchTemplateName=MY-LAUNCH-TEMPLATE
Names of instances can be assigned by specifying a Name
tag:
aws ec2 run-instances --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=MY-INSTANCE-NAME}]' --launch-template LaunchTemplateName=my-launch-template
Upvotes: 3