quotas

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 11 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 OfferedSageMakerTypes added in v0.42.0

func OfferedSageMakerTypes(ctx context.Context, lister ServiceQuotasLister, region string) ([]string, error)

OfferedSageMakerTypes returns the deduplicated, sorted set of ml.* instance types offered in a region. It is a thin wrapper over OfferedSageMakerTypesDetailed for callers that only need the type names.

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 SageMakerTypeQuota added in v0.42.0

type SageMakerTypeQuota struct {
	// InstanceType is the ml.*-prefixed type, e.g. "ml.g5.2xlarge".
	InstanceType string
	// TrainingJobLimit is the account limit for "training job usage" (the count
	// of concurrent instances of this type in training jobs). -1 when the region
	// exposes no training-job quota for the type.
	TrainingJobLimit float64
	// ManagedSpotEligible is true when the region exposes a "spot training job
	// usage" quota for the type — i.e. the type can be used with managed spot
	// training. (Managed spot is a billed-time discount, not a spot market, so
	// there is no per-type spot price to report; this only marks eligibility.)
	ManagedSpotEligible bool
}

SageMakerTypeQuota summarizes the per-type SageMaker service quotas relevant to discovery, extracted from the region's quota list without extra API calls.

func OfferedSageMakerTypesDetailed added in v0.42.0

func OfferedSageMakerTypesDetailed(ctx context.Context, lister ServiceQuotasLister, region string) ([]SageMakerTypeQuota, error)

OfferedSageMakerTypesDetailed returns per-type quota summaries for the ml.* instance types offered in a region, sorted by instance type. Quota names look like "ml.g5.2xlarge for training job usage"; the type is the part before " for " and the job type is the remainder. There is no SageMaker equivalent of EC2 DescribeInstanceTypes, so Service Quotas is the authoritative source for which ml.* types exist in a region — and, folded in here, for their per-type limits and managed-spot eligibility.

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 NewServiceQuotasClientFromConfig added in v0.42.0

func NewServiceQuotasClientFromConfig(cfg aws.Config) *ServiceQuotasClient

NewServiceQuotasClientFromConfig creates a service-quotas client from an injected aws.Config. Use this to share a config (e.g. a test's Substrate emulator, or an already-loaded config) rather than loading a fresh one.

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