Close Menu
geekfence.comgeekfence.com
    What's Hot

    Scotland and First-Person Screams Are Silent Hill: Townfall’s New Direction of Intimate Horror

    July 30, 2026

    The first 30 days of agentic AI governance: A practical checklist

    July 30, 2026

    Lowering AWS KMS decrypt API costs in EMR Spark jobs

    July 30, 2026
    Facebook X (Twitter) Instagram
    • About Us
    • Contact Us
    Facebook Instagram
    geekfence.comgeekfence.com
    • Home
    • UK Tech News
    • AI
    • Big Data
    • Cyber Security
      • Cloud Computing
      • iOS Development
    • IoT
    • Mobile
    • Software
      • Software Development
      • Software Engineering
    • Technology
      • Green Technology
      • Nanotechnology
    • Telecom
    geekfence.comgeekfence.com
    Home»Big Data»Lowering AWS KMS decrypt API costs in EMR Spark jobs
    Big Data

    Lowering AWS KMS decrypt API costs in EMR Spark jobs

    AdminBy AdminJuly 30, 2026No Comments7 Mins Read2 Views
    Facebook Twitter Pinterest LinkedIn Telegram Tumblr Email
    Lowering AWS KMS decrypt API costs in EMR Spark jobs
    Share
    Facebook Twitter LinkedIn Pinterest Email


    Modern organizations processing vast amounts of data on Amazon EMR with Apache Spark face a growing cost challenge. As the number of encrypted Amazon Simple Storage Service (Amazon S3) objects grows, AWS Key Management Service (AWS KMS) decrypt API calls multiply rapidly, driving up operational costs. Consider a retail organization processing hundreds of terabytes of customer transaction data daily in S3 encrypted with AWS KMS. Each Spark task accessing an encrypted S3 object triggers an AWS KMS decrypt API call. At scale, these calls accumulate into significant and often unexpected cost increases. This is especially true for workloads that require key auditability and cannot switch to S3 Bucket Keys. S3 Bucket Keys reduce AWS KMS request costs by decreasing the number of calls from S3 to AWS KMS. However, S3 Bucket Keys limit per-object key auditability in AWS CloudTrail, which might not meet the compliance requirements of some organizations.

    This post introduces practical techniques to reduce AWS KMS decrypt costs. You can reduce API call volume and lower costs without compromising encryption. It covers three techniques: optimizing file formats (including Apache Iceberg), aggregating data, and using AWS Glue Data Catalog partition indexes.

    Optimization techniques

    The following sections describe three techniques you can apply independently or together to reduce the number of AWS KMS decrypt API calls.

    Use data aggregation

    Data aggregation reduces redundant AWS KMS decrypt API calls by consolidating smaller files into larger blocks. When Spark reads many small files from S3, each file triggers its own decrypt call. By combining multiple small files into fewer, larger files, you can reduce the total number of AWS KMS API invocations. This technique is effective for read-heavy workloads that involve numerous small files stored on S3.

    You can use AWS CloudTrail to monitor changes in API call frequency and validate the effectiveness of data aggregation in reducing costs.

    Step 1: Benchmark baseline performance

    Before applying optimizations, establish baseline metrics to quantify improvements.

    from pyspark.sql import SparkSession
    import time
    
    spark = SparkSession.builder.appName("Baseline Job").getOrCreate()
    start_time = time.time()
    data = spark.read.format("csv").load("s3://amzn-s3-demo-bucket/data/")
    end_time = time.time()
    load_time = end_time - start_time
    print(f"Load time: {load_time:.2f} seconds")
    data_count = data.count()
    print(f"AWS KMS calls triggered: {data_count} rows processed")

    The following figure shows the number of AWS KMS Decrypt API calls captured in AWS CloudTrail. Use these baseline metrics to compare against optimized results in subsequent steps.

    Amazon Athena console displaying CloudTrail log query results with a KMS Decrypt API call events triggered during the baseline Spark job reading unoptimized CSV files from S3

    AWS CloudTrail log showing baseline AWS KMS Decrypt API call count

    Step 2: Aggregate files using Spark

    Consolidating smaller files into fewer, larger files stored in S3 minimizes redundant decrypt API calls.

    consolidated_data = data.coalesce(10)
    consolidated_data.write.mode("overwrite").parquet("s3://amzn-s3-demo-bucket/optimized-data/")

    Step 3: Rerun the job with optimized files

    Read the aggregated data created in Step 2 and compare the AWS KMS Decrypt API call count against the baseline metrics from Step 1.

    optimized_data = spark.read.parquet("s3://amzn-s3-demo-bucket/optimized-data/")
    optimized_data.count()

    The following figure shows the AWS CloudTrail logs after reading the aggregated data.

    Amazon Athena console displaying CloudTrail log query results with a reduced number of KMS Decrypt API call events after reading aggregated Parquet files

    AWS CloudTrail logs in Amazon Athena showing AWS KMS Decrypt API call count after data aggregation

    CloudTrail metrics comparison

    Track the number of API calls and observe the direct impact of data aggregation on reducing AWS KMS decrypt API calls for the same amount of data.

    The following figure compares the AWS KMS Decrypt API call count before and after data aggregation for the same dataset.

    Comparison chart showing AWS KMS Decrypt API call count for the same dataset, with a significant reduction after consolidating small CSV files into fewer aggregated Parquet files

    AWS KMS Decrypt API call comparison before and after data aggregation

    Aggregating small files into fewer large files reduces decrypt calls and shortens load time.

    Optimize file formats and compression

    Selecting appropriate file formats and applying compression minimizes the amount of data read from S3 and the number of AWS KMS decrypt operations.

    Columnar formats (Parquet/ORC)

    Columnar file formats like Parquet and ORC let Spark read only the required columns for analysis, which improves performance for analytical queries. For example, you can convert raw CSV data to Parquet to benefit from better I/O efficiency and query optimization.

    df = spark.read.format("csv") \
        .option("header", "true") \
        .option("inferSchema", "true") \
        .load("s3://emr-kms-demo/data/")
    
    # Set compression for Parquet files
    spark.conf.set("spark.sql.parquet.compression.codec", "snappy")
    
    df.write.format("parquet").save("s3://amzn-s3-demo-bucket/parquet-data/")

    Iceberg format

    Apache Iceberg is a modern table format designed for large-scale analytic datasets. It supports schema evolution, snapshot isolation, and time travel, making it an excellent choice for data lakes on S3. When used with PySpark, Apache Iceberg simplifies data management by automatically optimizing file layouts, handling partitions, and integrating with Spark catalogs.

    The following PySpark example uses Iceberg with Amazon EMR and S3:

    pyspark \
      --packages org.apache.iceberg:iceberg-spark-runtime-3.4_2.12:1.4.2 \
      --conf spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions \
      --conf spark.sql.catalog.spark_catalog=org.apache.iceberg.spark.SparkSessionCatalog \
      --conf spark.sql.catalog.spark_catalog.type=hadoop \
      --conf spark.sql.catalog.spark_catalog.warehouse=s3://amzn-s3-demo-bucket/iceberg-warehouse \
      --conf spark.sql.defaultCatalog=spark_catalog

    df = spark.read.format("csv") \
        .option("header", "true") \
        .option("inferSchema", "true") \
        .load("s3://amzn-s3-demo-bucket/data/")
    
    spark.conf.set("spark.sql.parquet.compression.codec", "snappy")
    
    # Write data to Iceberg table
    df.writeTo("iceberg_from_emr_data").using("iceberg").create()
    
    # Read from Iceberg table
    spark.read.table("iceberg_from_emr_data").show()

    Compression

    Using compression reduces data size and speeds up reads and writes between S3 and Spark. Note: ZSTD is the recommended and default compression codec for Iceberg, offering better compression ratios. For this demonstration, we use Snappy to illustrate the concept.

    spark.conf.set("spark.sql.parquet.compression.codec", "snappy")

    Compression not only minimizes I/O and network overhead but also accelerates job execution in distributed Spark environments.

    CloudTrail comparison on API calls

    The following figure shows the reduction in AWS KMS Decrypt API calls when using optimized file formats with compression.

    Comparison showing AWS KMS Decrypt API call count for Parquet files with Snappy compression

    AWS KMS Decrypt API calls on optimized file formats with compression

    The following table illustrates the reduction in AWS KMS decrypt calls when moving from raw, uncompressed CSV data to optimized Parquet files with compression enabled.

    Comparison showing AWS KMS Decrypt API call count for Uncompressed CSV vs Parquet files with Snappy compression

    AWS KMS Decrypt API call comparison for CSV and compressed Parquet with Snappy

    AWS Glue Data Catalog partition index

    Partitioning data helps Spark jobs retrieve subsets of relevant data, reducing scan ranges, and decrypt operations. Using AWS Glue Data Catalog partition indexes reduces scanning overhead and the number of AWS KMS API calls.

    Without a partition index, when Spark queries a partitioned table, AWS Glue Data Catalog returns all partitions by calling the GetPartitions API. Spark then reads every S3 object across all returned partitions. Because each S3 object is individually encrypted, Spark must call the AWS KMS Decrypt API once per object. More objects mean more decrypt calls and higher costs. With a partition index, AWS Glue performs server-side partition filtering, returning only matching partitions.

    Step 1: Baseline query without partition index

    Using an Amazon EMR Spark job:

    spark.sql("SELECT * FROM default.`kms-demoevents` WHERE year="2000" AND month="04"").count()

    Then check CloudTrail for the kms:Decrypt call count.

    The following figure shows the AWS KMS Decrypt API call count when running the baseline query without a partition index. Spark scans all partitions, resulting in a higher number of decrypt calls.

    Amazon Athena console displaying CloudTrail log query results showing the total number of AWS KMS Decrypt API calls triggered when querying without a partition index

    AWS KMS Decrypt API call count without a partition index

    Step 2: Add partition index and rerun the baseline query from Step 1

    In the AWS Management Console or through the AWS Command Line Interface (AWS CLI), create partition indexes and rerun the same baseline query from Step 1. Create partition indexes on the year and month columns. Then check CloudTrail for the kms:Decrypt call count.

    The following figure shows the AWS KMS Decrypt API call count after adding a partition index. With the partition index, AWS Glue filters partitions server-side, resulting in fewer S3 objects read and fewer decrypt calls.

    Amazon Athena console displaying CloudTrail log query results showing a reduced number of AWS KMS Decrypt API calls after adding a partition index on year and month columns, compared to the baseline query without partition index

    AWS KMS Decrypt API call count with a partition index

    Conclusion

    Optimizing EMR Spark jobs ensures cost-effective and efficient processing of encrypted data at scale. S3 Bucket Keys is the most effective way to reduce AWS KMS Decrypt API calls. The techniques covered in this post are additional optimizations that you can use together with S3 Bucket Keys for further cost reduction. You can also use them independently when S3 Bucket Keys cannot be used because of per-object auditability requirements in CloudTrail. Start implementing these strategies today to improve your Spark workload efficiency and achieve cost savings.

    We welcome your feedback. If you have questions or suggestions about this post, leave a comment below.


    About the author

    Naveen Jagathesan

    Naveen Jagathesan

    Naveen is a Senior Technical Account Manager at AWS and focuses on driving operational excellence for customers. Outside of work, he is an avid gym enthusiast.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

    Related Posts

    How NorthStar Anesthesia built a scheduling app for a workforce of 3,000 clinicians in weeks

    July 29, 2026

    Compliance Training Software: 5 Enterprise Providers

    July 28, 2026

    How to Store Petabytes of Data Without Renting It From the Cloud |

    July 27, 2026

    Data Science Case Study: The SCOPE Framework Guide

    July 26, 2026

    Why Modernizing Your CCM Environment on AWS Is Simpler Than You Think

    July 25, 2026

    How Alight Solutions achieved 55% cost savings with Amazon OpenSearch Service

    July 23, 2026
    Top Posts

    Understanding U-Net Architecture in Deep Learning

    November 25, 202567 Views

    The Next Paradigm in Efficient Inference Scaling – The Berkeley Artificial Intelligence Research Blog

    May 16, 202636 Views

    Hard-braking events as indicators of road segment crash risk

    January 14, 202634 Views
    Don't Miss

    Scotland and First-Person Screams Are Silent Hill: Townfall’s New Direction of Intimate Horror

    July 30, 2026

    Silent Hill games have rarely ventured beyond the titular mysterious town in Maine, but that’s…

    The first 30 days of agentic AI governance: A practical checklist

    July 30, 2026

    Lowering AWS KMS decrypt API costs in EMR Spark jobs

    July 30, 2026

    AI agents need security regression testing, not another checklist

    July 30, 2026
    Stay In Touch
    • Facebook
    • Instagram
    About Us

    At GeekFence, we are a team of tech-enthusiasts, industry watchers and content creators who believe that technology isn’t just about gadgets—it’s about how innovation transforms our lives, work and society. We’ve come together to build a place where readers, thinkers and industry insiders can converge to explore what’s next in tech.

    Our Picks

    Scotland and First-Person Screams Are Silent Hill: Townfall’s New Direction of Intimate Horror

    July 30, 2026

    The first 30 days of agentic AI governance: A practical checklist

    July 30, 2026

    Subscribe to Updates

    Please enable JavaScript in your browser to complete this form.
    Loading
    • About Us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • Terms and Conditions
    © 2026 Geekfence.All Rigt Reserved.

    Type above and press Enter to search. Press Esc to cancel.