I'm following the basic boto tutorial to try to connect to an EC2 instance. When I tried to create a simple instance to a basic Amazon Linux AMI, I got the following error:
import boto.ec2
conn = boto.ec2.connect_to_region("us-east-1")
conn.run_instances('ami-1ecae776')
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/boto/ec2/connection.py", line 973, in run_instances
verb='POST')
File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 1208, in get_object
raise self.ResponseError(response.status, response.reason, body)
boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request
InvalidParameterCombinationNon-Windows instances with a virtualization type of 'hvm' are currently not supported for this instance type.fb016420-47f3-4453-b0bc-ebd2f3c70ba5
I apologize if this has been addressed elsewhere in SO but I really did a thorough search, including trying the answers in 400 Bad Request while pulling instances with amazon. The date command on my machine and date on the remote aws servers seem to match so I'm not sure what could be causing this. Any suggestions would be appreciated.
The only thing you have specified is the AMI. That particular AMI is HVM-based and will work with all current generation EC2 instance types. However, the default value for instance_type in boto is m1.small and that older-generation instance type only supports PV virtualization.
So, to get your command running, you need to explicitly specify the instance_type parameter, like this:
conn.run_instances('ami-1ecae776', instance_type='t1.micro')
In addition to instance_type, you probably also want to provide a few other parameters in your call such as key_name, and security_groups. Otherwise, you won't be able to log into your instance.
Related
When trying to create an ECS instance via cli tools I get the error in subject and I can't find what it means. For example:
$ ./aliyun ecs RunInstances --Amount 1 --ImageId m-0xidtg6bbw1s8voux52d --InstanceType ecs.n1.medium --InstanceName Composer-Test-VM-1 --SecurityGroupId sg-0xi4w9isg0p1ytj1qbhf
ERROR: SDK.ServerError
ErrorCode: InvalidResourceType.NotSupported
Recommend:
RequestId: 1B3E65BD-D181-4552-9A58-599FC51924A7
Message: user order resource type [classic] not exists in [random]
I have credentials configured in ~/.aliyun/config.json.
The default region in config is us-east-1, the ImageId and SecurityGroupId are both in the same region.
I tried a few other instance types and either I get the same error message or [classic] is replaced by the prefix of the instance type. This leads me to think I can't create virtual machines from some of these instance types in my region but I have no idea why.
Does anyone know what is causing this specific error or where to find more documentation about it ?
I have found the culprit here. Although not stated (e.g. in --help) the --VSwitchId option is mandatory when specifying a --SecurityGroupId. The VSwitch needs to be in the same availability zone as your security group.
On this link, check out the following documentation under "Description":
For network configuration:
To create an instance in a VPC, you must specify a VPC and a VSwitch. One instance can belong only to one VSwitch.
When you specify VSwitchId, ensure that the security group and VSwitch specified by SecurityGroupId and VSwitchId belong to the same VPC.
If you specify both VSwitchId and PrivateIpAddress, ensure that the private IP address specified by PrivateIpAddress is within the CIDR block of the VSwitch.
PrivateIpAddress is dependent on VSwitchId. You cannot only specify the PrivateIpAddress parameter.
Also Note: The Alibaba Cloud product APIs are divided into RPC API and RESTful API. Most products use RPC style. When you use Alibaba Cloud CLI to call the interface, APIs of different styles have different calling methods.
Check out the following link: https://www.alibabacloud.com/help/doc-detail/110344.htm
Hope this helps!
I have an ec2 micro instance. I can start it from the console, ssh into it (using a .pem file) and visit the website it hosts.
Using the old ec2 CLI, I can start the instance and perform other actions including ssh and website access.
I am having trouble with the new ec2 CLI. When I do "aws ec2 start-instances --instance-ids i-xxx" I get the message "A client error (InvalidInstanceID.NotFound) occurred when calling the StartInstances operation: The instance ID 'i-xxx' does not exist".
Clearly the instance exists, so I don't what the message is really indicating.
Here is some of my thinking:
One difference between the old and new CLI is that the the later used .pem files whereas the new interface uses access key pairs. The instance has an access key pair associated with is, but have tried all the credentials I can find, and none of them change anything).
I tried created an IAM user and a new access key pair for it. The behavior in all cases is unchanged (start from console or old CLI, web access, ssh) but not using the new CLI.
I realize that there is a means for updating the access key pairs by detaching the volume (as described here), but the process looks a little scary to me.
I realize that I can clone another instance from the image, but the image is a little out of date, and I don't want to lose my changes.
Can anyone suggest what the message really means and what I can do to get around the problem?
The problem had to do with credentials. I had the correct environment
variables (AWS_ACCESS_KEY and AWS_SECRET_KEY) set. But they didn't match what was in my .aws/credentials file. That is, despite what it says here, the new CLI worked only when I had the environment variables and
the credentials file correct and in sync.
Configure your aws cli with "aws configure" in new cli instance with region in which your ec2 instance reside. and then try to give the same command. The instance should start.
I'd like to get EC2 instances metadata with Ansible and do something with those instances based on the metadata. However, ec2_facts wants to SSH into instances in order to get the metadata.
I believe it should be possible to obtain the instances metadata without SSH connections.
Could you help me with that please?
Thank you.
There is information you can retrieve about instances using the aws API but ec_facts does not use it. What that Ansible module does specifically is fetch metadata via http://169.254.169.254/latest/meta-data/ which can only be done from the instance itself.
Some more information about what instance data you wish to fetch would be helpful to know. At this time there is no aws cloud module in core that will retrieve general information about an instance but Ansible makes it easy to write one.
Here is an example of a module that returns information about instances that match a set of tags - https://github.com/edx/configuration/blob/master/playbooks/library/ec2_lookup
I would like to create a new instance based on my stored AMI.
I achieve this by the following code:
RunInstancesRequest rir = new RunInstancesRequest(imageId,1, 1);
// Code for configuring the settings of the new instance
...
RunInstancesResult runResult = ec2.runInstances(rir);
However, I cannot find a wait to "block"/wait until the instance is up and running apart from Thread.currentThread().sleep(xxxx) command.
On the other hand, StartInstancesResult and TerminateInstancesResult gives you a way to have access on the state of the instances and be able to monitor any changes. But, what about the state of a completely new instance?
boto3 has:
instance.wait_until_running()
From the boto3 docs:
Waits until this Instance is running. This method calls EC2.Waiter.instance_running.wait() which polls EC2.Client.describe_instances() every 15 seconds until a successful state is reached. An error is returned after 40 failed checks.
From the AWS CLI changelog for v1.6.0:
Add a wait subcommand that allows for a command to block until an AWS
resource reaches a given state (issue 992, issue 985)
I don't see this mentioned in the documentation, but the following worked for me:
aws ec2 start-instances --instance-ids "i-XXXXXXXX"
aws ec2 wait instance-running --instance-ids "i-XXXXXXXX"
The wait instance-running line did not finish until the EC2 instance was running.
I don't use Python/boto/botocore but assume it has something similar. Check out waiter.py on Github.
Waiting for the EC2 instance to get ready is a common pattern. In the Python library boto you also solve this with sleep calls:
reservation = conn.run_instances([Instance configuration here])
instance = reservation.instances[0]
while instance.state != 'running':
print '...instance is %s' % instance.state
time.sleep(10)
instance.update()
With this mechanism you will be able to poll when your new instance will come up.
Depending on what you are trying to do (and how many servers you plan on starting), instead of polling for the instance start events, you could install on the AMI a simple program/script that runs once when the instance starts and sends out a notification to that effect, i.e. to an AWS SNS Topic.
The process that needs to know about new servers starting could then subscribe to this SNS topic, and would receive a push notifications each time a server starts.
Solves the same problem from a different angle; your mileage may vary.
Go use Boto3's wait_until_running method:
http://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Instance.wait_until_running
You can use boto3 waiters,
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#waiters
for this ex: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Waiter.InstanceRunning
Or in Java https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/
I am sure there are waiters implemented in all the AWS sdks.
I am trying to launch a cluster of custom AMI images. AMI image is just Ubunutu 12.04 server image from Amazon free tier selection with Java installed (I actually want to create AMI with numpy and scipy). In fact, I created that image by launching the Ubuntu 12.04 instance with whirr and noop as a role. Then I installed Java, and in AWS online Console selected Create Image (EBS AMI). I am using same whirr recipe script I used to launch original ubuntu server with only image-id changed.
Whirr launches the image, it shows up in the console. Then it tries to run InitScript for noop and nothing happens. After 10min it throws exception caused by script running for too long. whirr.log containts record
error acquiring SFTPClient() (out of retries - max 7): Invalid packet: indicated length 1349281121 too large
I saw this error mentioned in one of the tutorials, suggested solution was to add line
whirr.bootstrap-user=ec2-user
to let JCloud know the username. I know this is the correct username and was used by default anyway. After adding the line, whirr.log shows authentification error, problem with public key.
Finally, when I use 'ubuntu' as user, the error is
Dying because - java.net.SocketTimeoutException: Read timed out
Here's file I use to launch the cluster
whirr.cluster-name=pineapple
whirr.instance-templates=1 noop
whirr.provider=aws-ec2
whirr.identity=${env:AWS_ACCESS_KEY_ID}
whirr.credential=${env:AWS_SECRET_ACCESS_KEY}
whirr.private-key-file=${sys:user.home}/.ssh/id_rsa
whirr.public-key-file=${sys:user.home}/.ssh/id_rsa.pub
whirr.env.repo=cdh4
whirr.hardware-id=t1.micro
whirr.image-id=us-east-1/ami-224cda4b
whirr.image-location=us-east-1b
The exception log will help us to solve your problem.
Also, setting the following may solve your issue.
whirr.cluster-user=<Clu>