1/5/2024 0 Comments Ec2 pricing![]() We will look at the terms section later, but for now, let’s focus on the product section. If you look at a single product, you’d find that it has a the following structure: [ The data is pulled directly from AWS docs, the same JSON endpoint their pricing page pulls it from, so the data is always up to date. So what gives? We’ll look at that in the next section. Results of running the codeĮxecuting this script will return a JSON document of almost 10.000 lines! In the document you will find 60 products, all of them considered an m5.large in Ireland. You can find all region names on the AWS Regions and Endpoints page. ‘EU (Ireland)’) instead of the Region Code (eg. ![]() Unfortunately, the Pricing API region requires the Region Name (eg. ![]() After one year of free usage you will be charged roughly around 15. If you expect that this will only return one result, however, you might be in for a surprise. For such load, you can simply go with Amazon Free Tier which can easily withstand this load. In other words, you pay the same for a reservation as running an actual instance. We will query the Pricing API so it will only return prices for EC2 instances located in the ‘EU (Ireland)’ region, with the m5.large instance type. Now you’re paying the UnusedCapacityReservation price for one instance and the Used price plus the AllocatedCapacityReservation price for another. We will then merge those results into an array called products. This will give us blocks of 100 results (as specified in the pagesize). The paginator will return an iterator, which we can loop over. This data cannot be returned in one request, which is why we use a paginator. The Pricing API will return a lot of data - we’ll get to that in a second. If you don’t and then run your script in another AWS Region, it might fail because it can’t find the Pricing API in that region. This is the only region the Pricing API is available in, so you should hardcode it. The important part here is specifying the region as us-east-1. The pricing_client is defined as pricing_client = boto3.client('pricing', region_name='us-east-1'). Paginator = pricing_client.get_paginator( 'get_products')įor 38 lines of code, there is already a lot to digest here. Pricing_client = boto3.client( 'pricing', region_name= 'us-east-1') Let’s set up some basic scaffolding: import json We will write a python script that uses boto3 (the python SDK for AWS) to query the API, process the results, and store the data in a JSON file. It supports Intel, AMD, and Arm processors, and offers 400 Gbps Ethernet networking. In this blog post, we will focus on the first type. Amazon EC2 offers more than 500 instances (servers) to choose from based on processors, storage, memory, networking, OS, and pricing models.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |