Skip to main content

AWS S3 Storage Summary

In a Nutshell
What will I learn?In this tutorial we will generate a simple S3 usage report that shows AWS S3 buckets with current storage usage.
Difficulty

What you'll need

Software & Services

Permissions & Access

AWS provide an existing ReadOnlyAccess IAM Policy that covers all of the permissions needed for this tutorial. You can simply attach this AWS provided IAM Policy to your existing IAM User, Group or Role

Attach Existing IAM Policy
Screenshot: Attach Existing IAM Policy

Tutorial

In each of the examples below we will take advantage of several of the environment variables that are loaded and set when we activate a set of credentials in AWSH

AWSH❯
env | grep ^AWS_
AWS_ACCOUNT_ALIAS=dummy-account
AWS_DEFAULT_REGION=eu-central-1
AWS_SESSION_EXPIRATION=2022-11-28 16:05:01
AWS_SECRET_ACCESS_KEY=f3hfuss77fffdUToVx+T1iFNV+6tLgL3dUhCJY6jhPccRQW
AWS_ID_NAME=dummy-account/[email protected]
AWS_ACCOUNT_NUMBER=011111221051
AWS_ACCESS_KEY_ID=ASIAQO7RUGABCDEFYXLOK
AWS_TOKEN_EXPIRY=1669651501

We will use these environment variables to generate useful report names. This tutorial also makes use of one of the built-in commands available in AWSH awsh report-s3-usage which allows us to generate report and print it to console.

Simple Format Report

  • Create a simple text summary report

    AWSH❯
    awsh report-s3-usage
  • Here is a sample output generated from the S3 usage report

    asciicast

Markdown Format Report

  • Get the data from the AWS API using AWSH

    AWSH❯
    awsh report-s3-usage -f pipe
  • The Markdown format report is plain text but can be converted into many other common formats (HTML, PDF, MS Word, etc). One of our favourite online converters is https://dillinger.io/ or the extensions available for Microsoft VS Code

HTML Format Report

  • Create an HTML header for our report

    AWSH❯
    cat > "${HOME}/workspace/${AWS_ACCOUNT_NUMBER}-AWS-S3-Summary.html" <<EOF
    <html>
    <head>
    <title>AWS S3 Usage Summary for A/C: ${AWS_ACCOUNT_NUMBER}</title>
    </head>
    <body>
    <h1>AWS S3 Usage Summary for A/C: ${AWS_ACCOUNT_NUMBER}</h1>
    <p>
    This S3 report was generated using AWSH on $(date)
    for AWS Account ${AWS_ACCOUNT_NUMBER} with alias: ${AWS_ACCOUNT_ALIAS}
    </p>
    <div>
    EOF

  • Get the data from the AWS API using AWSH

    AWSH❯
    awsh report-s3-usage -f html >> "${HOME}/workspace/${AWS_ACCOUNT_NUMBER}-AWS-S3-Summary.html"
  • Add the HTML page footer to make a valid HTML page

    AWSH❯
    echo "</div></body></html>" >> "${HOME}/workspace/${AWS_ACCOUNT_NUMBER}-AWS-S3-Summary.html"

Now that you've had a look around why not check out the full documentation here.


Want to find out more?

At Hestio, we have taken our experience with designing and building on cloud to codify these patterns and made them available as a low-code pattern library for AWS. Why spend time and effort on reinventing the wheel when it's already a solved problem? Would you start developing office productivity software in a world where Microsoft Office already exists?

If you'd like to find out about worX, our low-code patterns library for AWS you can read more here or get in touch today to schedule a demo.

If you'd like to find out more about the products and services Hestio has to offer, select one of the options below.