question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get more than 10 results from ec2 get_spot_placement_scores

See original GitHub issue

Describe the bug

I want to get more than 10 results from get_spot_placement_scores method, but it returns maximum 10 results. Is there any way to get more than 10 results? I checked this method can take “NextToken” parameter, but there’s no “NextToken” from the response… Is this limited to use? or do I have some mistake?

Steps to reproduce

import boto3

session = boto3.session.Session(profile_name='dev')
ec2 = session.client('ec2', region_name='us-west-2')

response = ec2.get_spot_placement_scores(
    InstanceTypes=['g3s.xlarge'],
    TargetCapacity=1,
    SingleAvailabilityZone=True
)

print(response)
print(len(response['SpotPlacementScores']))

Expected behavior I want to get “NextToken” string from the response, and want to get more than 10 results from single request Thank you for helping me.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kdailycommented, Nov 15, 2021

Hi @odobenuskr,

Thanks for your question. The operation GetSpotPlacementScores is paginated and by default returns 10 items at a time. You’ll need to use a paginator to help you continue making subsequent requests. You’ll need to do something like the following:

import boto3

session = boto3.session.Session(profile_name='dev')
ec2 = session.client('ec2', region_name='us-west-2')

# Create a reusable Paginator
paginator = ec2.get_paginator('get_spot_placement_scores')

page_iterator = paginator.paginate(
    InstanceTypes=['g3s.xlarge'],
    TargetCapacity=1,
    SingleAvailabilityZone=True
)

for page in page_iterator:
    print(page['Contents'])

You can read more about this here:

I hope this helps! If you’re still having an issue, feel free to let us know.

0reactions
james-sungjae-leecommented, Nov 17, 2021

Thank you for checking this problem, @kdaily !

I think this API response is limited by AWS, so I will try another way.

Thank you for helping me!

Read more comments on GitHub >

github_iconTop Results From Across the Web

GetSpotPlacementScores - Amazon Elastic Compute Cloud
Calculates the Spot placement score for a Region or Availability Zone based on the specified target capacity and compute requirements.
Read more >
get-spot-placement-scores — AWS CLI 2.4.18 Command ...
get-spot-placement-scores is a paginated operation. Multiple API calls may be issued in order to retrieve the entire data set of results.
Read more >
Spot placement score - Amazon Elastic Compute Cloud
The Spot placement score feature helps you to find the optimal Amazon Regions or Availability Zones for your Amazon EC2 Spot workloads.
Read more >
Spot Placement Score (SPS) - Amazon EC2 Spot Workshops
... above parameters, use this command. aws ec2 get-spot-placement-scores --cli-input-json file://./sps-input.json. Spot placement score returns the top 10 ...
Read more >
ec2 - Go Packages
If you attempt this operation on EC2 Classic, you receive an ... If the instance has more than one // network interface, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found