close
Amazon Web Services (AWS)

Script to report on Amazon AppStream 2.0 usage

Here is a sample script that you can use to report on Amazon AppStream 2.0 usage:

#!/bin/bash

# Define the AWS region to use
REGION=us-west-2

# Define the date range for the report
START_DATE=$(date -d "30 days ago" +"%Y-%m-%d")
END_DATE=$(date +"%Y-%m-%d")

# Get the total number of AppStream 2.0 sessions in the specified date range
TOTAL_SESSIONS=$(aws appstream describe-sessions \
                 --start-time "$START_DATE" \
                 --end-time "$END_DATE" \
                 --query 'Sessions[].SessionId' \
                 --output text \
                 --region "$REGION" | wc -l)

# Get the total number of AppStream 2.0 fleet hours in the specified date range
TOTAL_HOURS=$(aws appstream describe-session-details \
                 --start-time "$START_DATE" \
                 --end-time "$END_DATE" \
                 --query 'SessionDetails[].SessionTime' \
                 --output text \
                 --region "$REGION" | awk '{total+=$1} END {printf "%.2f", total}')

# Print the report
echo "Report for Amazon AppStream 2.0 Usage"
echo "Date Range: $START_DATE to $END_DATE"
echo "Total Sessions: $TOTAL_SESSIONS"
echo "Total Hours: $TOTAL_HOURS"

This script uses the AWS CLI to retrieve information about AppStream 2.0 sessions and fleet hours in the specified date range. The output is a report that includes the total number of sessions and total number of hours for the specified date range.

You can run this script on a regular basis, such as daily or weekly, to monitor your AppStream 2.0 usage and keep track of the resources that you are consuming. You can also modify the script to add additional information to the report, such as the number of active fleets or the total cost of your AppStream 2.0 usage.

Leave a Response