Using aws costexplorer with fsx
TypeScriptIn this program, we're going to set up an AWS FSx file system and integrate AWS Cost Explorer to monitor and analyze its costs. FSx provides fully managed third-party file systems with the native compatibility and features of the filesystems. AWS Cost Explorer is a service that enables you to visualize, understand, and manage your AWS costs and usage over time.
First, we'll provision an Amazon FSx file system using Pulumi's AWS package. Subsequently, we'll create a Cost Category in AWS Cost Explorer to categorize the cost related to FSx, making it easier to analyze the associated costs separately from other services.
Setting up the FSx File System
We choose to use AWS Managed Microsoft FSx as an example, which lets you use fully native Windows file systems in AWS.
Here's a high-level overview of the resources we will be creating:
- AWS Fsx File System: This resource creates and manages an Amazon FSx for Windows File Server file system.
- AWS Cost Explorer Cost Category: A Cost Category is a rule-based group of cost and usage data, which can be associated with FSx using tags or other dimensions.
Let's dive into the code:
import * as aws from "@pulumi/aws"; // Create an Amazon FSx for Windows File Server file system. const fileSystem = new aws.fsx.WindowsFileSystem("myFsxWindowsFileSystem", { // Resource properties here like storage capacity, subnet, vpc, and tags... // For example: activeDirectoryId: "d-1234567890", // Your AD directory ID. storageCapacity: 300, // The storage capacity (GiB) of the file system. throughputCapacity: 8, // The throughput (MBps) of the file system. subnetIds: ["subnet-12345"], // The subnets that the file system will be accessible from. // ...other configuration options... }); // Create a Cost Explorer Cost Category to filter costs related to the FSx file system. const fsxCostCategory = new aws.costexplorer.CostCategory("fsxCostCategory", { name: "FSxCost", rules: JSON.stringify({ "Rules": [ { "Rule": { "And": [{ "Dimensions": { "Key": "SERVICE", "Values": ["Amazon FSx"] } }] }, "Value": "FSxCostCategoryValue" } ], }), ruleVersion: "CostCategoryExpression.v1", }); export const fileSystemId = fileSystem.id; export const fileSystemArn = fileSystem.arn; export const costCategoryId = fsxCostCategory.id;
Note that you will need to replace placeholder values like
activeDirectoryId
andsubnetIds
with actual values from your setup.Explanation of the Program:
- The
aws.fsx.WindowsFileSystem
resource creates an FSx file system. You need to specify properties like the Active Directory ID, VPC details, and storage options according to your needs. - The
aws.costexplorer.CostCategory
resource creates a new Cost Category. The rule we provided filters costs where the service is"Amazon FSx"
. You can refine it further based on tags or other dimensions.
Finally, we export the IDs and ARNs of the created resources, which can be used to reference these resources in other parts of your infrastructure or for automation purposes.
Keep in mind that in order to run this Pulumi program successfully, the AWS provider needs to be configured with appropriate credentials. This setup is usually done outside the program itself, often through the AWS CLI or environment variables.