Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boto3: Spot Instance Creation

Tags:

I'm trying to create a spot instance using boto3. Although I follow the API documentation, I receive an exception I couldn't be able to figure out. The code I'm using is:

import boto3 import datetime client = boto3.client('ec2') response = client.request_spot_instances(     DryRun=False,     SpotPrice='0.10',     ClientToken='string',     InstanceCount=1,     Type='one-time',     LaunchSpecification={         'ImageId': 'ami-fce3c696',         'KeyName': 'awskey.pem',         'SecurityGroups': ['sg-709f8709'],         'InstanceType': 'm4.large',         'Placement': {             'AvailabilityZone': 'us-east-1a',         },         'BlockDeviceMappings': [             {                 'Ebs': {                     'SnapshotId': 'snap-f70deff0',                     'VolumeSize': 100,                     'DeleteOnTermination': True,                     'VolumeType': 'gp2',                     'Iops': 300,                     'Encrypted': False                 },             },         ],          'EbsOptimized': True,         'Monitoring': {             'Enabled': True         },         'SecurityGroupIds': [             'sg-709f8709',         ]     } ) 

And I receive the following exception:

botocore.exceptions.ClientError: An error occurred (InvalidParameterValue) when calling the RequestSpotInstances operation: Value () for parameter groupId is invalid. The value cannot be empty 

The thing is there is no groupId parameter in the request in the API documentation.

Am I missing something?

like image 400
jatha Avatar asked Mar 01 '16 11:03

jatha


People also ask

How do I create a VPC in boto3?

Create a VPC First thing's first let's import the boto3 library in Python create an 'ec2' resource object using the method 'resource()' after that using the create_vpc() method create a virtual private network by passing the CIDR notation as an argument to named parameter 'CidrBlock'.

How do you create a security group on boto3?

You can create a new security group using the create_security_group() method, and assign it to our VPC. Then you can define inbound rules to only allow SSH port number 22 as shown below.

What is waiter boto3?

Waiters use a client's service operations to poll the status of an AWS resource and suspend execution until the AWS resource reaches the state that the waiter is polling for or a failure occurs while polling. Using clients, you can learn the name of each waiter that a client has access to: import boto3 s3 = boto3.


1 Answers

Although it's not specified in the API documentation, apparently 'SecurityGroups' parameter requires the names of the security groups, not the IDs.

Changing to the group name solved the issue.

Thanks for anyone bothered to read the question in the first place.

like image 177
jatha Avatar answered Oct 04 '22 15:10

jatha