Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

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

Am I missing something?

1 Answer

0 votes
by (44.4k points)

Changing the group name instead of the IDs in "SecurityGroups" solved it for me. It is not mentioned in the Documentation.

Related questions

0 votes
1 answer

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer
asked Jul 23, 2019 in AWS by yuvraj (19.1k points)
0 votes
1 answer
asked Jul 23, 2019 in AWS by yuvraj (19.1k points)
+1 vote
1 answer

Browse Categories

...