### Example: Fetch Lambda Pricing (Python CLI) Source: https://github.com/aws-samples/service-price-lists-collector/blob/main/README.md Example command to fetch pricing for the AWS Lambda service in the ap-northeast-1 region. ```bash #For Lambda python pricing_cli.py --region ap-northeast-1 --service-code AWSLambda ``` -------------------------------- ### Example: Fetch S3 Pricing (Python CLI) Source: https://github.com/aws-samples/service-price-lists-collector/blob/main/README.md Example command to fetch pricing for the Amazon S3 service in the eu-west-1 region. ```bash #For S3 python pricing_cli.py --region eu-west-1 --service-code AmazonS3 ``` -------------------------------- ### Example: Fetch EC2 Pricing (Python CLI) Source: https://github.com/aws-samples/service-price-lists-collector/blob/main/README.md Example command to fetch pricing for the Amazon EC2 service in the ap-southeast-1 region. ```bash #For EC2 python pricing_cli.py --region ap-southeast-1 --service-code AmazonEC2 ``` -------------------------------- ### Get Help and View Options (Python CLI) Source: https://github.com/aws-samples/service-price-lists-collector/blob/main/README.md This command displays the help message and lists all available command-line options for the pricing CLI tool. ```bash python pricing_cli.py --help ``` -------------------------------- ### AWS Credential Configuration Examples (Bash) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Illustrates four methods for configuring AWS credentials: environment variables, AWS credentials file, AWS CLI configuration, and IAM roles. Each method is shown with the necessary commands and a sample CLI execution. ```bash # Method 1: Environment Variables export AWS_ACCESS_KEY_ID='AKIAIOSFODNN7EXAMPLE' export AWS_SECRET_ACCESS_KEY='wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY' export AWS_DEFAULT_REGION='us-east-1' python pricing_cli.py --region us-east-1 --service-code AmazonEC2 # Method 2: AWS Credentials File # Create ~/.aws/credentials with: # [default] # aws_access_key_id = AKIAIOSFODNN7EXAMPLE # aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY python pricing_cli.py --region us-east-1 --service-code AmazonEC2 # Method 3: AWS CLI Configuration aws configure # Follow prompts to enter access key, secret key, region, and output format python pricing_cli.py --region us-east-1 --service-code AmazonEC2 # Method 4: IAM Role (for EC2/ECS instances) # Attach IAM role with required permissions to the instance # No additional configuration needed python pricing_cli.py --region us-east-1 --service-code AmazonEC2 ``` -------------------------------- ### Example: Fetch RDS Pricing (Python CLI) Source: https://github.com/aws-samples/service-price-lists-collector/blob/main/README.md Example command to fetch pricing for the Amazon RDS service in the us-east-2 region. ```bash #For RDS python pricing_cli.py --region us-east-2 --service-code AmazonRDS ``` -------------------------------- ### Discover AWS Service Codes using AWS CLI Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Shows how to use the AWS Command Line Interface (CLI) to list all available AWS service codes, filter them, and retrieve detailed information about a specific service. This requires the AWS CLI to be installed and configured. ```bash # Use AWS CLI to list all service codes aws pricing describe-services --region us-east-1 --query 'Services[].ServiceCode' --output table # Expected output: # ---------------------------- # | DescribeServices | # +---------------------------+ # | AmazonEC2 | # | AmazonS3 | # | AmazonRDS | # | AWSLambda | # | AmazonDynamoDB | # |... # Filter for specific services aws pricing describe-services --region us-east-1 --query 'Services[?contains(ServiceCode, `Amazon`)].ServiceCode' --output table # Get detailed information about a service aws pricing describe-services --region us-east-1 --filters "Type=TERM_MATCH,Field=ServiceCode,Value=AmazonEC2" ``` -------------------------------- ### Combine Consolidation and Truncation (CLI) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Fetches pricing data for multiple AWS services, consolidates them, and then truncates the combined data to include only specified columns. This is an efficient way to get a focused dataset from various services. ```bash python pricing_cli.py --region us-east-1 --service-code AmazonEC2,AmazonS3,AmazonRDS --consolidate --truncate SKU,ServiceCode,PricePerUnit,Currency ``` -------------------------------- ### Discover AWS Service Codes Programmatically (Python) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Demonstrates how to programmatically retrieve all AWS service codes using the PricingDataManager class from the pricing_cli library. It includes examples for printing all services and filtering for specific ones. ```python # Programmatically retrieve all service codes from pricing_cli import PricingDataManager manager = PricingDataManager(region='us-east-1') all_services = manager.get_all_service_codes() # Print all available services print(f"Total services: {len(all_services)}") for service in sorted(all_services): print(f" - {service}") # Search for specific services ec2_services = [s for s in all_services if 'EC2' in s] print(f"EC2-related services: {ec2_services}") # Output: EC2-related services: ['AmazonEC2', 'AmazonEC2ContainerRegistry', ...] ``` -------------------------------- ### Download Pricing Data Programmatically (Python) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Initiates the download of pricing data for a specified AWS service using the Python API. This example shows how to instantiate PricingDataManager and retrieve the Price List ARN as a prerequisite for downloading. ```python from pricing_cli import PricingDataManager manager = PricingDataManager(region='us-west-2', output_dir='./downloads') # Get price list ARN price_list_arn = manager.get_price_list('AmazonEC2') ``` -------------------------------- ### Download Pricing Data using Python Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Downloads pricing data for a specified AWS service and region using the PricingDataManager. It requires the AWS SDK for Python (Boto3) to be installed and configured. The function returns the file path of the downloaded CSV or indicates failure. ```python if price_list_arn: file_path = manager.download_pricing_data( price_list_arn=price_list_arn, service_code='AmazonEC2', file_format='csv' ) if file_path: print(f"Successfully downloaded: {file_path}") # Output: Successfully downloaded: ./downloads/pricing-AmazonEC2-us-west-2.csv else: print("Download failed") ``` -------------------------------- ### Get Price List ARN for EC2 (Python) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Retrieves the AWS Price List ARN (Amazon Resource Name) for a specific service, such as AmazonEC2, using the PricingDataManager class. This ARN is often required for further programmatic interactions with AWS pricing data. ```python from pricing_cli import PricingDataManager manager = PricingDataManager(region='us-east-1') # Get the price list ARN for EC2 price_list_arn = manager.get_price_list('AmazonEC2') print(f"Price List ARN: {price_list_arn}") ``` -------------------------------- ### Initialize and Use PricingDataManager in Python Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Demonstrates initializing the PricingDataManager class, checking AWS permissions, retrieving all available AWS service codes, and validating service codes and the AWS region. This requires the 'boto3' and 'click' libraries. ```python from pricing_cli import PricingDataManager # Initialize the manager with region and output directory manager = PricingDataManager(region='us-east-1', output_dir='./pricing_data') # Check AWS permissions manager._check_permissions() # Get all available AWS service codes all_services = manager.get_all_service_codes() print(f"Found {len(all_services)} AWS services") # Output: Found 200+ AWS services (varies by region) # Validate specific service codes before processing try: manager.validate_service_codes(['AmazonEC2', 'AmazonS3', 'AmazonRDS']) print("All service codes are valid") except ValueError as e: print(f"Validation failed: {e}") # Validate the region try: manager.validate_region() print(f"Region {manager.region} is valid") except ValueError as e: print(f"Invalid region: {e}") ``` -------------------------------- ### Enable Debug Mode for Troubleshooting (Bash) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Explains how to run the pricing_cli script with the `--debug` flag to enable detailed error messages and stack traces. This is crucial for diagnosing issues during development or operation. ```bash # Run with debug mode enabled python pricing_cli.py --region us-east-1 --service-code AmazonEC2 --debug # When an error occurs, full stack trace is displayed: # Traceback (most recent call last): # File "pricing_cli.py", line 311, in fetch_pricing # downloaded_files = pricing_manager.process_service_codes(service_codes, output_format) # File "pricing_cli.py", line 103, in process_service_codes # price_list_arn = self.get_price_list(code) # ... # Full exception details for debugging ``` -------------------------------- ### Fetch Pricing for Multiple AWS Services via CLI Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Command to download and process pricing data for multiple AWS services simultaneously using the command-line interface. Services are specified as a comma-separated list. ```bash # Fetch pricing for EC2, S3, and RDS python pricing_cli.py --region us-west-2 --service-code AmazonEC2,AmazonS3,AmazonRDS # Expected output: # ================================================== # AWS Pricing Data Fetcher - Region: us-west-2 # ================================================== # Fetching pricing for services: AmazonEC2, AmazonS3, AmazonRDS... # # [1/3] Processing AmazonEC2... # Downloading AmazonEC2 [####################################] 100% # ✓ Successfully downloaded pricing for AmazonEC2 # # [2/3] Processing AmazonS3... # Downloading AmazonS3 [####################################] 100% # ✓ Successfully downloaded pricing for AmazonS3 # # [3/3] Processing AmazonRDS... # Downloading AmazonRDS [####################################] 100% # ✓ Successfully downloaded pricing for AmazonRDS # # Download completed! 3 file(s) downloaded. # # Output files: # - ./pricing-AmazonEC2-us-west-2.csv # - ./pricing-AmazonS3-us-west-2.csv # - ./pricing-AmazonRDS-us-west-2.csv ``` -------------------------------- ### Fetch Pricing for All AWS Services via CLI Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Command to download pricing data for all available AWS services within a specified region using the command-line interface. This command may take a significant amount of time due to the number of services. ```bash # Fetch pricing for all services in EU Central (Frankfurt) python pricing_cli.py --region eu-central-1 --all-services # Expected output: # ================================================== # AWS Pricing Data Fetcher - Region: eu-central-1 # ================================================== # # [1/200] Processing AmazonEC2... # Downloading AmazonEC2 [####################################] 100% # ✓ Successfully downloaded pricing for AmazonEC2 # # [2/200] Processing AmazonS3... # Downloading AmazonS3 [####################################] 100% # ✓ Successfully downloaded pricing for AmazonS3 # ... # [200/200] Processing AWSLambda... # # Warning: No pricing data found for: # - ServiceCode1 (no pricing data available in eu-central-1) # - ServiceCode2 (no pricing data available in eu-central-1) # # Download completed! 198 file(s) downloaded. ``` -------------------------------- ### Consolidate Pricing for Multiple Services (Python CLI) Source: https://github.com/aws-samples/service-price-lists-collector/blob/main/README.md This command fetches pricing for multiple services (e.g., AmazonEC2, AmazonS3) in a region (e.g., us-east-1) and consolidates them into a single file using the `--consolidate` flag. ```bash python pricing_cli.py --region us-east-1 --service-code AmazonEC2,AmazonS3 --consolidate ``` -------------------------------- ### Fetch Pricing for a Single AWS Service via CLI Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Command to download pricing data for a specific AWS service in a given region using the command-line interface. Requires the Python script `pricing_cli.py` to be executable. ```bash # Fetch EC2 pricing in US East (N. Virginia) python pricing_cli.py --region us-east-1 --service-code AmazonEC2 # Expected output: # ================================================== # AWS Pricing Data Fetcher - Region: us-east-1 # ================================================== # Fetching pricing for services: AmazonEC2... # # [1/1] Processing AmazonEC2... # Downloading AmazonEC2 [####################################] 100% # ✓ Successfully downloaded pricing for AmazonEC2 # # Download completed! 1 file(s) downloaded. # # Output file: ./pricing-AmazonEC2-us-east-1.csv ``` -------------------------------- ### Consolidate and Save to Custom Directory Structure (CLI) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Fetches pricing data for multiple services, consolidates them, and saves the output to a specific directory path, potentially creating nested directories. This command aids in organized data storage for reporting. ```bash mkdir -p ./pricing_reports/2025/november python pricing_cli.py --region us-east-1 --service-code AmazonEC2,AmazonS3 --output-dir ./pricing_reports/2025/november --consolidate ``` -------------------------------- ### Fetch Specific AWS Service Pricing (Python CLI) Source: https://github.com/aws-samples/service-price-lists-collector/blob/main/README.md This command fetches pricing information for a specific AWS service (e.g., AmazonEC2) in a given region (e.g., us-east-1). It demonstrates the basic usage of the pricing CLI tool. ```bash python pricing_cli.py --region us-east-1 --service-code AmazonEC2 ``` -------------------------------- ### Fetch All AWS Services Pricing (Python CLI) Source: https://github.com/aws-samples/service-price-lists-collector/blob/main/README.md This command retrieves pricing data for all available AWS services within a specified region (e.g., us-west-2). It utilizes the `--all-services` flag for a comprehensive data collection. ```bash python pricing_cli.py --region us-west-2 --all-services ``` -------------------------------- ### Error Handling for Invalid Inputs (Bash) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Demonstrates how the command-line interface (CLI) handles invalid service codes, regions, and missing AWS credentials. This helps users understand expected error messages and troubleshoot configuration issues. ```bash # Handle invalid service code python pricing_cli.py --region us-east-1 --service-code InvalidService # Expected output: # Error: Invalid service code(s): InvalidService. Use 'aws pricing describe-services' to find valid codes. # Handle invalid region python pricing_cli.py --region invalid-region --service-code AmazonEC2 # Expected output: # Error: Invalid region 'invalid-region'. Valid regions: ap-northeast-1, ap-southeast-1, ... # Handle missing AWS credentials unset AWS_ACCESS_KEY_ID unset AWS_SECRET_ACCESS_KEY python pricing_cli.py --region us-east-1 --service-code AmazonEC2 # Expected output: # Credential Error: AWS credentials not found. Please ensure credentials are configured: # 1. Environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY) # 2. AWS credentials file (~/.aws/credentials) # 3. IAM role for EC2 instance or container ``` -------------------------------- ### Batch Pricing Data Collection using Shell and Python Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt This script automates the process of collecting AWS pricing data for multiple regions and services. It utilizes a Python script (pricing_cli.py) to fetch, consolidate, and format pricing information, saving it to a structured directory. The script requires AWS credentials and the pricing_cli.py script to be available. ```shell REGIONS=("us-east-1" "us-west-2" "eu-west-1" "ap-southeast-1") SERVICES="AmazonEC2,AmazonS3,AmazonRDS,AWSLambda" OUTPUT_BASE="./pricing_data" for region in "${REGIONS[@]}"; do echo "Processing region: $region" # Create region-specific directory mkdir -p "$OUTPUT_BASE/$region" # Fetch, consolidate, and truncate pricing data python pricing_cli.py \ --region "$region" \ --service-code "$SERVICES" \ --output-dir "$OUTPUT_BASE/$region" \ --consolidate \ --truncate "SKU,ServiceCode,PricePerUnit,Currency,InstanceType,Location" \ --format csv echo "Completed processing for $region" done echo "All regions processed successfully" # Execute the script: # chmod +x batch_pricing_collection.sh # ./batch_pricing_collection.sh ``` -------------------------------- ### Consolidate and Export Multiple Services as JSON (CLI) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Consolidates pricing data from multiple AWS services and exports the result in JSON format. This command is useful for generating comprehensive, structured pricing reports. ```bash python pricing_cli.py --region eu-west-1 --service-code AmazonEC2,AmazonRDS --consolidate --format json ``` -------------------------------- ### Export Pricing Data in JSON Format (Python CLI) Source: https://github.com/aws-samples/service-price-lists-collector/blob/main/README.md This command fetches pricing for a service (e.g., AmazonEC2) in a region (e.g., us-east-1) and exports the data in JSON format using the `--format json` option. ```bash python pricing_cli.py --region us-east-1 --service-code AmazonEC2 --format json ``` -------------------------------- ### Save Pricing Data to Custom Directory (CLI) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Saves fetched AWS service pricing data to a specified custom directory. This allows users to organize their downloaded pricing files according to their project needs. ```bash python pricing_cli.py --region us-east-1 --service-code AmazonEC2 --output-dir /tmp/pricing_data ``` -------------------------------- ### Export S3 Pricing as Excel (CLI) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Exports pricing data for a specified AWS service (e.g., AmazonS3) in Excel format. This command facilitates data analysis in spreadsheet applications. ```bash python pricing_cli.py --region us-west-2 --service-code AmazonS3 --format excel ``` -------------------------------- ### Handle Service Without Pricing Data (Python) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Demonstrates how to handle cases where pricing data is not available for a requested service. The get_price_list method returns None, which can be checked programmatically to provide user feedback or alternative actions. ```python from pricing_cli import PricingDataManager manager = PricingDataManager(region='us-east-1') # Handle service without pricing data price_list_arn = manager.get_price_list('NonExistentService') if price_list_arn is None: print("No pricing data available for this service") ``` -------------------------------- ### Save AWS Pricing to Specific Directory (Python CLI) Source: https://github.com/aws-samples/service-price-lists-collector/blob/main/README.md This command fetches pricing for a service (e.g., AmazonS3) in a region (e.g., eu-central-1) and saves the output files to a custom directory (e.g., /tmp/pricing) using the `--output-dir` option. ```bash python pricing_cli.py --region eu-central-1 --service-code AmazonS3 --output-dir /tmp/pricing ``` -------------------------------- ### Consolidate and Truncate Pricing (Python CLI) Source: https://github.com/aws-samples/service-price-lists-collector/blob/main/README.md This command fetches pricing for multiple services (e.g., AmazonEC2, AmazonS3) in a region (e.g., us-east-1), consolidates them, and truncates the output to specified columns using both `--consolidate` and `--truncate` flags. ```bash python pricing_cli.py --region us-east-1 --service-code AmazonEC2,AmazonS3 --consolidate --truncate SKU,PricePerUnit,Currency ``` -------------------------------- ### Batch Processing Script for Pricing Data (Bash) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Provides a basic bash script structure intended for automating the collection of pricing data across multiple AWS regions and services. This script would typically involve loops and conditional logic to iterate through desired parameters. ```bash #!/bin/bash ``` -------------------------------- ### Programmatic Consolidation of Pricing Data (Python) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Programmatically processes pricing data for specified AWS services and consolidates the downloaded files into a single CSV. This method utilizes the PricingDataManager class for structured data handling and offers flexibility in specifying output directories. ```python from pricing_cli import PricingDataManager manager = PricingDataManager(region='us-east-1', output_dir='./output') # Process services and get file paths files = manager.process_service_codes(['AmazonEC2', 'AmazonS3'], 'csv') # Consolidate the downloaded files consolidated_file = manager.consolidate_files(files, 'csv') print(f"Consolidated file created: {consolidated_file}") ``` -------------------------------- ### Extract Specific Columns from EC2 Pricing (CLI) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Fetches pricing data for a specific AWS service (e.g., AmazonEC2) and retains only a predefined set of columns. This is useful for focusing on essential pricing details and reducing data volume. ```bash python pricing_cli.py --region us-east-1 --service-code AmazonEC2 --truncate SKU,PricePerUnit,Currency,InstanceType,Location ``` -------------------------------- ### Find AWS Service Codes using AWS CLI Source: https://github.com/aws-samples/service-price-lists-collector/blob/main/README.md This AWS CLI command retrieves a list of available service codes for a specific region (e.g., us-east-1). The output is formatted as a table for easy readability. ```bash aws pricing describe-services --region us-east-1 --query 'Services[].ServiceCode' --output table ``` -------------------------------- ### Truncate Output Columns (Python CLI) Source: https://github.com/aws-samples/service-price-lists-collector/blob/main/README.md This command fetches pricing for a service (e.g., AmazonEC2) in a region (e.g., us-east-1) and keeps only specified columns (e.g., SKU, PricePerUnit, Currency) using the `--truncate` option. ```bash python pricing_cli.py --region us-east-1 --service-code AmazonEC2 --truncate SKU,PricePerUnit,Currency ``` -------------------------------- ### Programmatic Truncation of Pricing Data (Python) Source: https://context7.com/aws-samples/service-price-lists-collector/llms.txt Programmatically truncates an existing pricing data file by keeping only specified columns. This function is part of the PricingDataManager class and allows for fine-grained control over the data output. ```python from pricing_cli import PricingDataManager manager = PricingDataManager(region='us-east-1', output_dir='./output') # Truncate an existing pricing file columns_to_keep = ['SKU', 'PricePerUnit', 'Currency', 'InstanceType'] truncated_file = manager.truncate_data( './output/pricing-AmazonEC2-us-east-1.csv', columns_to_keep ) print(f"Truncated file: {truncated_file}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.