Roy "rat" Tokeshi

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:


# Define the AWS region to use

# 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.

read more
Amazon Web Services (AWS)

Use the CreateUsageReportSubscription operation.

the steps you need to follow to create a Python script that reports on Amazon AppStream usage using the CreateUsageReportSubscription operation.

Install the AWS SDK for Python (Boto3)
You will need to install the AWS SDK for Python (Boto3) in order to interact with Amazon AppStream and AWS services from your Python script. You can install it using pip with the following command:
pip install boto3

Import the required modules
In your Python script, import the required modules:
import boto3

Create a client for AppStream 2.0
Create a client for AppStream 2.0 with the following code:
appstream = boto3.client('appstream')

Call the CreateUsageReportSubscription operation
You can use the following code to call the CreateUsageReportSubscription operation:
response = appstream.create_usage_report_subscription()

Verify the response
Verify the response to ensure that the operation was successful. You can use the following code to check the response:
if response['ResponseMetadata']['HTTPStatusCode'] == 200:
print("Usage report subscription created successfully.")
print("Error creating usage report subscription.")

This is a basic example to get you started with creating a Python script that reports on Amazon AppStream usage using the CreateUsageReportSubscription operation. You can find more information about the operation and the required parameters in the AWS documentation:

read more
Amazon Web Services (AWS)

How do I migrate an Amazon WorkSpaces instance using the AWS CLI?

You can migrate an Amazon WorkSpaces instance from one directory to another using the modify-workspace-properties command in the AWS CLI. Here’s an example bash script that demonstrates the process:


# Set the AWS region

# The ID of the Workspace to migrate

# The ID of the target directory

# Migrate the Workspace to the target directory
aws workspaces modify-workspace-properties \
    --region $REGION \
    --workspace-id $WORKSPACE_ID \
    --directory-id $TARGET_DIRECTORY_ID

In this example, you would replace ws-xxxxxxxx with the ID of the Amazon WorkSpaces instance you want to migrate, and replace d-xxxxxxxxxx with the ID of the target directory. The modify-workspace-properties command will then migrate the specified Workspace to the target directory.

read more
Amazon Web Services (AWS)Infrastructure-as-Code (IaC)

How to script AWS CLI to describe instances on Amazon WorkSpaces

Here’s an example of a bash script that uses the AWS CLI to describe Amazon WorkSpaces instances:

# Define the AWS region to use
# Use the AWS CLI to describe the Amazon Workspaces instances
INSTANCES=$(aws workspaces describe-workspaces --region $REGION)
# Print the information for each instance
echo "Information for all Amazon Workspaces instances:"
echo $INSTANCES | jq -r '.Workspaces[] | "\(.DirectoryId) \(.UserName) \(.WorkspaceId) \(.State)"'

In this example, the script uses the aws workspaces describe-workspaces command to get information about all Amazon WorkSpaces instances in the specified region (us-west-2 in this case). The output of the command is stored in the INSTANCES variable. The script then uses the jq command to parse the JSON output and print the DirectoryId, UserName, WorkspaceId, and State of each instance.

You’ll need to have the AWS CLI and jq installed on your system to run this script.

read more
Amazon Web Services (AWS)

AWS Artifact on-demand access to third-party compliance reports is now generally available

The AWS Artifact Reports page now offers on-demand access to security compliance reports of third-party software vendors who sell their products through AWS Marketplace. AWS customers can download and review the reports shared by the ISV to accelerate their procurement cycle. The reports are only accessible to customers who have been granted access to AWS Marketplace Vendor Insights for a specific ISV. The reports are available in all commercial AWS Regions where AWS Artifact is available. To get started, customers can refer to the AWS Artifact console, Third-Party reports FAQ section, API Documentation, CloudTrail Integration, and AWS Artifact Forum.

AWS Artifact is a web-based tool from Amazon Web Services (AWS) that provides on-demand access to compliance reports, security and privacy audit documents, and other agreements related to AWS services and products. AWS Artifact makes it easy for customers to download these documents and manage their compliance obligations. It also helps customers understand the compliance status of their AWS environment.

read more

When Searching Amazon Athena for Service events

Here is a quick query when you are looking for events in CloudTrail. First, export to Athena.
Then create a query that references the table: Now you are ready for some SQL

In the example below I am getting entries from “TableName” and the service is Amazon WorkSpaces. That has a source of

FROM TableName
WHERE eventsource = '' 
ORDER by eventtime
LIMIT 100;
read more
Amazon Web Services (AWS)

Monitor your WorkSpaces using CloudWatch metrics

WorkSpaces and Amazon CloudWatch are integrated, so you can gather and analyze performance metrics. You can monitor these metrics using the CloudWatch console, the CloudWatch command line interface, or programmatically using the CloudWatch API. CloudWatch also allows you to set alarms when you reach a specified threshold for a metric.

For more information about using CloudWatch and alarms, see the Amazon CloudWatch User Guide.


To get CloudWatch metrics, enable access on port 443 on the AMAZON subset in the us-east-1 Region. For more information, see IP address and port requirements for WorkSpaces.

WorkSpaces metrics
Dimensions for WorkSpaces metrics
Monitoring example

read more
Amazon Web Services (AWS)Cloud

Relative Mouse Offset

Relative Mouse Offset
By default, during users’ streaming sessions, AppStream 2.0 transmits information about mouse movements to the streaming instance by using absolute coordinates and rendering the mouse movements locally. For graphics-intensive applications, such as computer-aided design (CAD)/computer-aided manufacturing (CAM) software or video games, mouse performance improves when relative mouse mode is enabled. Relative mouse mode uses relative coordinates, which represent how far the mouse moved since the last frame, rather than the absolute x-y coordinate values within a window or screen. When relative mouse mode is enabled, AppStream 2.0 renders the mouse movements remotely.

Users can enable this feature during their AppStream 2.0 streaming sessions by doing either of the following:

Pressing Ctrl+Shift+F8

Choosing Relative Mouse Position [Ctrl+Shift+F8] from the Settings menu on the AppStream 2.0 toolbar in the top left area of their streaming session window. This method works when they use classic mode or Desktop View.
read more

How to find instances available in the AWS LAX Local Zone

I recently needed to create a custom xml file to configure the instance types available in the LAX local zone for a Citrix Virtual Apps Deployment. In AWS parlance, you are looking to “Find an Instance type using the AWS CLI” This is what the command looks like for the LAX 1a local zone:

aws ec2 describe-instance-type-offerings --location-type "availability-zone" --filters Name=location,Values=us-west-2-lax-1a --region us-west-2

If you are looking in LAX 1b:

aws ec2 describe-instance-type-offerings --location-type "availability-zone" --filters Name=location,Values=us-west-2-lax-1b --region us-west-2

Example output from the LAX 1a local zone
read more
1 2 3 4 5 6
Page 4 of 6