quotas

package
v0.36.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package quotas queries AWS Service Quotas and current EC2 usage to determine whether a given instance type can be launched under an account's limits.

EC2 service quotas are expressed as per-family vCPU counts rather than instance counts. This package handles the mapping from instance type to quota family (e.g., p4d.24xlarge → FamilyP) and computes remaining capacity.

Typical usage:

client, err := quotas.NewClient(ctx)
info, err := client.GetQuotas(ctx, "us-east-1")
ok, msg := client.CanLaunch("p4d.24xlarge", 96, info, false)

Results are cached per region for 5 minutes to avoid redundant API calls.

Index

Constants

View Source
const (
	// On-Demand vCPU quotas
	QuotaCodeStandard = "L-1216C47A" // Running On-Demand Standard instances
	QuotaCodeF        = "L-74FC7D96" // Running On-Demand F instances
	QuotaCodeG        = "L-DB2E81BA" // Running On-Demand G instances
	QuotaCodeP        = "L-417A185B" // Running On-Demand P instances
	QuotaCodeX        = "L-7295265B" // Running On-Demand X instances
	QuotaCodeInf      = "L-1945791B" // Running On-Demand Inf instances
	QuotaCodeTrn      = "L-2C3B7624" // Running On-Demand Trn instances

	// Spot vCPU quotas
	QuotaCodeSpotStandard = "L-34B43A08" // All Standard Spot Instance Requests
	QuotaCodeSpotF        = "L-88CF9481" // All F Spot Instance Requests
	QuotaCodeSpotG        = "L-3819A6DF" // All G and VT Spot Instance Requests
	QuotaCodeSpotP        = "L-7212CCBC" // All P Spot Instance Requests
	QuotaCodeSpotX        = "L-E3A00192" // All X Spot Instance Requests
	QuotaCodeSpotInf      = "L-B5D1601B" // All Inf Spot Instance Requests
	QuotaCodeSpotTrn      = "L-5480EFD2" // All Trn Spot Instance Requests
)

Service Quota codes for EC2

Variables

This section is empty.

Functions

func QuotaIncreaseCommand

func QuotaIncreaseCommand(region string, family QuotaFamily, desiredValue int32, spot bool) string

QuotaIncreaseCommand generates AWS CLI command to request quota increase

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client handles quota operations

func NewClient

func NewClient(ctx context.Context) (*Client, error)

NewClient creates a quota client using the default credential chain. Returns error if AWS credentials are not available.

func NewClientFromConfig

func NewClientFromConfig(cfg aws.Config) *Client

NewClientFromConfig creates a quota client with an injected AWS config. Use this in tests to point the client at a Substrate emulator.

func (*Client) CanLaunch

func (c *Client) CanLaunch(instanceType string, vCPUs int32, quotas *QuotaInfo, spot bool) (bool, string)

CanLaunch checks if an instance can be launched given quotas

func (*Client) GetQuotas

func (c *Client) GetQuotas(ctx context.Context, region string) (*QuotaInfo, error)

GetQuotas retrieves quota information for a region

type QuotaFamily

type QuotaFamily string

QuotaFamily represents instance family groupings for Service Quotas

const (
	FamilyStandard QuotaFamily = "Standard" // A, C, D, H, I, M, R, T, Z
	FamilyF        QuotaFamily = "F"        // FPGA
	FamilyG        QuotaFamily = "G"        // Graphics (g4dn, g5, g6)
	FamilyP        QuotaFamily = "P"        // GPU Training (p3, p4, p5)
	FamilyX        QuotaFamily = "X"        // Memory optimized
	FamilyInf      QuotaFamily = "Inf"      // Inferentia
	FamilyTrn      QuotaFamily = "Trn"      // Trainium
)

func GetQuotaFamily

func GetQuotaFamily(instanceType string) QuotaFamily

GetQuotaFamily maps instance type to quota family

type QuotaInfo

type QuotaInfo struct {
	Region string // AWS region this snapshot covers, e.g. "us-east-1"

	// On-Demand quotas — maximum vCPUs per family
	OnDemand map[QuotaFamily]int32

	// Spot quotas — maximum vCPUs per family for Spot instances
	Spot map[QuotaFamily]int32

	// Current usage — vCPUs currently in use (running + pending) per family
	Usage map[QuotaFamily]int32

	RunningInstances     int32     // Current count of running+pending instances in this region
	RunningInstancesMax  int32     // Per-region instance count limit (typically 20 for new accounts)
	LastUpdated          time.Time // When this snapshot was fetched
	CredentialsAvailable bool      // False when quotas were estimated due to missing credentials
}

QuotaInfo holds quota limits and current usage for a single region, as returned by Client.GetQuotas.

type SageMakerQuota

type SageMakerQuota struct {
	Name  string
	Code  string
	Value float64
}

SageMakerQuota holds a single SageMaker service quota entry.

type ServiceQuotasClient

type ServiceQuotasClient struct {
	// contains filtered or unexported fields
}

ServiceQuotasClient wraps the AWS Service Quotas API for SageMaker queries.

func NewServiceQuotasClient

func NewServiceQuotasClient(ctx context.Context) (*ServiceQuotasClient, error)

NewServiceQuotasClient creates a new client for querying service quotas.

func (*ServiceQuotasClient) ListSageMakerInstanceQuotas

func (c *ServiceQuotasClient) ListSageMakerInstanceQuotas(ctx context.Context, region string) ([]SageMakerQuota, error)

ListSageMakerInstanceQuotas returns all SageMaker ml.* instance quota entries for the given region. Only quotas whose name starts with "ml." are returned.

type ServiceQuotasLister

type ServiceQuotasLister interface {
	ListSageMakerInstanceQuotas(ctx context.Context, region string) ([]SageMakerQuota, error)
}

ServiceQuotasLister can list SageMaker instance quotas.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL