Hi, I want to ask about my <issue> from the <#C046...
# contributors
i
Hi, I want to ask about my issue from the #C046GMHQ6NM channel. I’m willing to help with adding calculation on CloudFront Function on infracost, but I’m quite confused with how the product and price filter actually work. Can somebody explain how it works? When I try to query the prices from infracost graphql API I don’t think it’s as complete as the pricing list in AWS
a
Hi Lewis - let me take a look into this and come back to you shortly
The problem with the query is the filter on region - CloudFront Functions operate on edge locations so don't have a region in the pricing data. If you remove that you'll get all of the SKUs The SKU is in the DB -
Copy code
{
  "data": {
    "products": [
      {
        "productFamily": "Request",
        "sku": "QAZUUEJG8GARJCET",
        "region": null,
        "prices": [
          {
            "USD": "0"
          },
          {
            "USD": "1e-7"
          }
        ]
      }
    ]
  }
}
i
How do I translate the filter into code? I’m using the SKU just to check the price component existence. I think all of the infracost code does not use SKU as filter.
My plan is using this
1e-7
price value and multiply it with the usage value. for example if I had this value in
infracost-usage.yml
:
Copy code
resource_usage:
  aws_cloudfront_function:
    monthly_requests: 200000
my expected value is 200,000 * 0,00000001 which equals to 0,02$
Is there any specific attribute that I can use to query that specific price component?
a
So the first price in this case is for the first 2m executions and the second price is per 1m subsequent
Copy code
{
  "4c91cb67406f635cb0de79c946589924-4243263383b2346485ee7f237500dfc0": [
    {
      "USD": "0.0000000000",
      "unit": "FunctionExecutions",
      "priceHash": "4c91cb67406f635cb0de79c946589924-4243263383b2346485ee7f237500dfc0",
      "description": "$0 for First 2,000,000 CloudFront Function Executions",
      "endUsageAmount": "2000000",
      "purchaseOption": "on_demand",
      "startUsageAmount": "0",
      "effectiveDateStart": "2024-10-01T00:00:00Z"
    },
    {
      "USD": "0.0000001000",
      "unit": "FunctionExecutions",
      "priceHash": "4c91cb67406f635cb0de79c946589924-4243263383b2346485ee7f237500dfc0",
      "description": "$0.10 per 1,000,000 CloudFront Function Executions",
      "endUsageAmount": "Inf",
      "purchaseOption": "on_demand",
      "startUsageAmount": "2000000",
      "effectiveDateStart": "2024-10-01T00:00:00Z"
    }
  ]
}
So this query might help?
Copy code
{
  products(
    filter: {
      vendorName: "aws"
    
      sku: "QAZUUEJG8GARJCET"
      service: "AmazonCloudFront"
    }
  ) {
    productFamily
    sku
    region
    prices {
      startUsageAmount
    
      USD
    }
  }
}
Start Usage amount isn't included in the product filters so it couldn't be filtered on that
i
is there any attribute I can use to get that price component? I’m trying to translate the query into the golang code.
Copy code
func (r *CloudfrontFunction) monthlyRequestsCostComponent() *schema.CostComponent {
	return &schema.CostComponent{
		Name:            "Total number of invocations",
		Unit:            "1M invocations",
		UnitMultiplier:  decimal.NewFromInt(1000000),
		MonthlyQuantity: floatPtrToDecimalPtr(r.MonthlyRequests),
		ProductFilter: &schema.ProductFilter{
			VendorName:       strPtr("aws"),
			Service:          strPtr("AmazonCloudFront"),
			ProductFamily:    strPtr("Request"),
			AttributeFilters: []*schema.AttributeFilter{
				
			},
		},
		PriceFilter: &schema.PriceFilter{
			PurchaseOption: strPtr("on_demand"),
		},
		UsageBased: true,
	}
}
How do I know which attribute I can use for filtering just by using the graphql API?
a
Attributes for this are fairly limited -
Copy code
{
  "group": "CloudFront-Functions",
  "operation": "Execution",
  "usagetype": "Executions-CloudFrontFunctions",
  "servicecode": "AmazonCloudFront",
  "servicename": "Amazon CloudFront",
  "groupDescription": "CloudFront Function executions"
}
Price filters can be seen here -> https://github.com/infracost/infracost/blob/master/internal/schema/filters.go#L12-L22 Would this solve it?
Copy code
PriceFilter: &schema.PriceFilter{
   PurchaseOption: strPtr("on_demand"),
   StartUsageAmount: strPtr("2000000"),
}
i
I end up with this filter:
Copy code
ProductFilter: &schema.ProductFilter{
			VendorName:    strPtr("aws"),
			Service:       strPtr("AmazonCloudFront"),
			ProductFamily: strPtr("Request"),
			AttributeFilters: []*schema.AttributeFilter{
				{Key: "usagetype", Value: strPtr("Executions-CloudFrontFunctions")},
				{Key: "groupDescription", ValueRegex: regexPtr("CloudFront Function")},
			},
		},
		PriceFilter: &schema.PriceFilter{
			PurchaseOption:   strPtr("on_demand"),
			StartUsageAmount: strPtr("2000000"),
		},
		UsageBased: true,
The price calculation seems as expected. I’ll prepare the PR
PR delivered here @adventurous-nail-5992. this resource is usage based cost component. my question is how do I finish the “Added test cases without usage-file” task?
Hi guys, any problems on the PR above?
l
@icy-hydrogen-80135 thanks! It looks great. I don’t think “Added test cases without usage-file” is applicable for this resource.