Documentation
¶
Overview ¶
Package aws provides AWS cloud provider implementation
Package aws provides service client implementations
Index ¶
- func EffectiveRegion(rec common.Recommendation) string
- func IsRegionAgnostic(rec common.Recommendation) bool
- func NewEC2Client(cfg aws.Config) provider.ServiceClient
- func NewEC2ClientDirect(cfg aws.Config) *ec2.Client
- func NewElastiCacheClient(cfg aws.Config) provider.ServiceClient
- func NewMemoryDBClient(cfg aws.Config) provider.ServiceClient
- func NewOpenSearchClient(cfg aws.Config) provider.ServiceClient
- func NewRDSClient(cfg aws.Config) provider.ServiceClient
- func NewRecommendationsClient(cfg aws.Config) provider.RecommendationsClient
- func NewRedshiftClient(cfg aws.Config) provider.ServiceClient
- func NewSavingsPlansClient(cfg aws.Config, planType sptypes.SavingsPlanType) provider.ServiceClient
- type ConfigLoader
- type EC2Client
- type OrganizationsClient
- type OrganizationsPaginator
- type Provider
- func (p *Provider) DisplayName() string
- func (p *Provider) GetAccounts(ctx context.Context) ([]common.Account, error)
- func (p *Provider) GetCredentials() (provider.Credentials, error)
- func (p *Provider) GetDefaultRegion() string
- func (p *Provider) GetRecommendationsClient(ctx context.Context) (provider.RecommendationsClient, error)
- func (p *Provider) GetRegions(ctx context.Context) ([]common.Region, error)
- func (p *Provider) GetServiceClient(ctx context.Context, service common.ServiceType, region string) (provider.ServiceClient, error)
- func (p *Provider) GetSupportedServices() []common.ServiceType
- func (p *Provider) IsConfigured() bool
- func (p *Provider) Name() string
- func (p *Provider) SetConfigLoader(loader ConfigLoader)
- func (p *Provider) SetEC2Client(client EC2Client)
- func (p *Provider) SetOrganizationsPaginator(paginator OrganizationsPaginator)
- func (p *Provider) SetSTSClient(client STSClient)
- func (p *Provider) ValidateCredentials(ctx context.Context) error
- type RecommendationsClientAdapter
- func (r *RecommendationsClientAdapter) GetAllRecommendations(ctx context.Context) ([]common.Recommendation, error)
- func (r *RecommendationsClientAdapter) GetRICoverageMap(ctx context.Context, lookbackDays int, regions []string) (recommendations.PoolCoverageMap, error)
- func (r *RecommendationsClientAdapter) GetRIUtilization(ctx context.Context, lookbackDays int, region string) ([]recommendations.RIUtilization, error)
- func (r *RecommendationsClientAdapter) GetRecommendations(ctx context.Context, params *common.RecommendationParams) ([]common.Recommendation, error)
- func (r *RecommendationsClientAdapter) GetRecommendationsForService(ctx context.Context, service common.ServiceType) ([]common.Recommendation, error)
- func (r *RecommendationsClientAdapter) SetRecLookbackPeriod(period string)
- type STSClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EffectiveRegion ¶
func EffectiveRegion(rec common.Recommendation) string
EffectiveRegion returns the region to use for region-filter matching. Savings Plans recommendations never populate the top-level rec.Region (GetSavingsPlansPurchaseRecommendation is account-level and carries no region parameter -- see applyRecommendationFilters); EC2Instance Savings Plans instead carry their recommended region in Details.Region (SavingsPlanDetails, populated by parser_sp.go's extractEC2SPFields). Falling back to it here means a region/include_regions filter matches EC2Instance SP recs on their real region instead of dropping them via an always-empty top-level Region. Compute/SageMaker/Database SP recs are genuinely region-agnostic (Details.Region stays "" for them), so this still returns "" for those, and IsRegionAgnostic is what decides that such a rec is exempt from region filtering (see #1495).
The Details fallback is confined to ProviderAWS. common.SavingsPlanDetails is a shared type that Azure's savingsplans client also asserts on, so exporting this predicate (#1582) made it reachable with a non-AWS rec whose Details mean something else. Only AWS builds Savings Plans recommendations today and parser_sp.go stamps ProviderAWS on every one, so the gate changes no behavior now; it keeps the AWS-only reading from outliving that invariant.
func IsRegionAgnostic ¶
func IsRegionAgnostic(rec common.Recommendation) bool
IsRegionAgnostic reports whether rec legitimately belongs to no single region and must therefore be exempt from both region filters: an account-level Savings Plan (Compute/SageMaker/Database), which GetSavingsPlansPurchaseRecommendation returns without any region because the plan applies account-wide.
The CommitmentSavingsPlan check is load-bearing, not decorative. An empty effective region is NOT by itself proof that a rec is region-agnostic: every reservation parser in parser_services.go writes rec.Region only under `if <svc>Details.Region != nil`, so an EC2/RDS/ElastiCache/ OpenSearch/Redshift/MemoryDB rec whose Cost Explorer payload omitted the region field lands here with Region == "" while still being a single-region purchase. Treating those as region-agnostic would let a rec of unknown region survive an explicit "us-east-1 only" filter and be bought in whatever region the service client happens to resolve. A reservation rec with no region is dropped by an include filter (its region cannot be shown to match) and kept by an exclude filter (it cannot be shown to be excluded) -- the same conservative direction each filter had before Savings Plans support was added.
CommitmentSavingsPlan alone is likewise not enough. Only the account-level plan types (Compute, SageMaker, Database) belong to no region; an EC2Instance Savings Plan is region-SCOPED, and extractEC2SPFields (recommendations/parser_sp.go) yields Region == "" whenever Cost Explorer omitted SavingsPlansDetails or its Region field, because aws.ToString maps a nil pointer to "". Exempting those would reopen exactly the hole the paragraph above closes for reservations, just for EC2Instance SPs. So the exemption requires POSITIVE evidence that the plan is account-level: isAccountLevelSPPlanType must recognize the plan type, and anything unknown (nil Details, a non-SavingsPlanDetails payload, a plan type this build has never heard of) stays region-scoped and is filtered conservatively rather than exempted.
ProviderAWS is required for the same reason EffectiveRegion requires it: this exemption is a statement about AWS Savings Plans products, and both common.CommitmentSavingsPlan and common.SavingsPlanDetails are shared types another provider could populate with different semantics.
func NewEC2Client ¶
func NewEC2Client(cfg aws.Config) provider.ServiceClient
NewEC2Client creates a new EC2 service client.
func NewEC2ClientDirect ¶
NewEC2ClientDirect creates a new EC2 client returning the concrete type (needed for ListConvertibleReservedInstances which is not part of the generic provider interface).
func NewElastiCacheClient ¶
func NewElastiCacheClient(cfg aws.Config) provider.ServiceClient
NewElastiCacheClient creates a new ElastiCache service client.
func NewMemoryDBClient ¶
func NewMemoryDBClient(cfg aws.Config) provider.ServiceClient
NewMemoryDBClient creates a new MemoryDB service client.
func NewOpenSearchClient ¶
func NewOpenSearchClient(cfg aws.Config) provider.ServiceClient
NewOpenSearchClient creates a new OpenSearch service client.
func NewRDSClient ¶
func NewRDSClient(cfg aws.Config) provider.ServiceClient
NewRDSClient creates a new RDS service client.
func NewRecommendationsClient ¶
func NewRecommendationsClient(cfg aws.Config) provider.RecommendationsClient
NewRecommendationsClient creates a new recommendations client.
func NewRedshiftClient ¶
func NewRedshiftClient(cfg aws.Config) provider.ServiceClient
NewRedshiftClient creates a new Redshift service client.
func NewSavingsPlansClient ¶
func NewSavingsPlansClient(cfg aws.Config, planType sptypes.SavingsPlanType) provider.ServiceClient
NewSavingsPlansClient creates a Savings Plans service client scoped to one AWS plan type. The four per-plan-type slugs (Compute, EC2Instance, SageMaker, Database) each get their own client instance via the AWS provider's GetServiceClient dispatch — see provider.go.
Types ¶
type ConfigLoader ¶
type ConfigLoader interface {
LoadDefaultConfig(ctx context.Context, optFns ...func(*config.LoadOptions) error) (aws.Config, error)
}
ConfigLoader interface for loading AWS config (enables mocking).
type EC2Client ¶
type EC2Client interface {
DescribeRegions(ctx context.Context, params *ec2.DescribeRegionsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeRegionsOutput, error)
}
EC2Client interface for EC2 operations (enables mocking).
type OrganizationsClient ¶
type OrganizationsClient interface {
ListAccounts(ctx context.Context, params *organizations.ListAccountsInput, optFns ...func(*organizations.Options)) (*organizations.ListAccountsOutput, error)
}
OrganizationsClient interface for Organizations operations (enables mocking).
type OrganizationsPaginator ¶
type OrganizationsPaginator interface {
HasMorePages() bool
NextPage(ctx context.Context, optFns ...func(*organizations.Options)) (*organizations.ListAccountsOutput, error)
}
OrganizationsPaginator interface for Organizations pagination (enables mocking).
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements the provider.Provider interface for AWS.
func NewAWSProvider ¶
func NewAWSProvider(cfg *provider.ProviderConfig) (*Provider, error)
NewAWSProvider creates a new AWS provider instance.
Profile resolution order:
- config.AWSProfile (typed field, preferred)
- config.Profile (deprecated overload — kept for backwards compatibility)
func (*Provider) DisplayName ¶
DisplayName returns the human-readable provider name.
func (*Provider) GetAccounts ¶
GetAccounts returns all accessible AWS accounts.
func (*Provider) GetCredentials ¶
func (p *Provider) GetCredentials() (provider.Credentials, error)
GetCredentials returns AWS credentials.
func (*Provider) GetDefaultRegion ¶
GetDefaultRegion returns the default AWS region.
Priority order:
- p.region if explicitly set on the provider.
- p.cfg.Region if the caller pre-populated cfg (e.g. tests with a synthetic config) — checked BEFORE IsConfigured to avoid the SDK's credentials/config chain overwriting a caller-supplied region with the ambient AWS_REGION / ~/.aws/config default.
- The SDK-loaded region (via IsConfigured → loadConfig).
- "us-east-1" as a last-resort default.
Step 2 is what fixes #96: previously this function called IsConfigured() unconditionally, which triggers cfgOnce.Do(loadConfig) and lets the SDK's credentials/config chain populate p.cfg.Region from the developer's ambient environment, masking a region the test had set explicitly. Reading the already-set p.cfg.Region first keeps test fixtures honest while still falling through to the SDK chain when no caller has touched cfg.
func (*Provider) GetRecommendationsClient ¶
func (p *Provider) GetRecommendationsClient(ctx context.Context) (provider.RecommendationsClient, error)
GetRecommendationsClient returns a recommendations client.
func (*Provider) GetRegions ¶
GetRegions returns all available AWS regions using EC2 DescribeRegions API.
func (*Provider) GetServiceClient ¶
func (p *Provider) GetServiceClient(ctx context.Context, service common.ServiceType, region string) (provider.ServiceClient, error)
GetServiceClient returns a service client for the specified service and region.
func (*Provider) GetSupportedServices ¶
func (p *Provider) GetSupportedServices() []common.ServiceType
GetSupportedServices returns the list of services supported by AWS provider. Savings Plans are exposed as four distinct services (one per AWS plan type) so users can configure term/payment defaults per plan type via ServiceConfig.
func (*Provider) IsConfigured ¶
IsConfigured checks if AWS credentials are available. The config is loaded at most once (thread-safe via sync.Once) to avoid data races on concurrent calls.
func (*Provider) SetConfigLoader ¶
func (p *Provider) SetConfigLoader(loader ConfigLoader)
SetConfigLoader sets the config loader (for testing).
func (*Provider) SetEC2Client ¶
SetEC2Client sets the EC2 client (for testing).
func (*Provider) SetOrganizationsPaginator ¶
func (p *Provider) SetOrganizationsPaginator(paginator OrganizationsPaginator)
SetOrganizationsPaginator sets the organizations paginator (for testing).
func (*Provider) SetSTSClient ¶
SetSTSClient sets the STS client (for testing).
type RecommendationsClientAdapter ¶
type RecommendationsClientAdapter struct {
// contains filtered or unexported fields
}
RecommendationsClientAdapter adapts the recommendations client to the provider interface.
func NewRecommendationsClientDirect ¶
func NewRecommendationsClientDirect(cfg aws.Config) *RecommendationsClientAdapter
NewRecommendationsClientDirect creates a new recommendations client returning the concrete type (needed for GetRIUtilization which is not part of the generic provider interface).
func (*RecommendationsClientAdapter) GetAllRecommendations ¶
func (r *RecommendationsClientAdapter) GetAllRecommendations(ctx context.Context) ([]common.Recommendation, error)
GetAllRecommendations gets recommendations for all supported services.
func (*RecommendationsClientAdapter) GetRICoverageMap ¶
func (r *RecommendationsClientAdapter) GetRICoverageMap(ctx context.Context, lookbackDays int, regions []string) (recommendations.PoolCoverageMap, error)
GetRICoverageMap returns the per-pool RI coverage % over the last lookbackDays days, keyed by "region:instance_type:account" (or "region:instance_type:engine:account" for RDS) so the apply helper can look up per-linked-account coverage. Caller passes the regions to scan; CE returns coverage filtered to that region and grouped by LINKED_ACCOUNT + INSTANCE_TYPE.
func (*RecommendationsClientAdapter) GetRIUtilization ¶
func (r *RecommendationsClientAdapter) GetRIUtilization(ctx context.Context, lookbackDays int, region string) ([]recommendations.RIUtilization, error)
GetRIUtilization gets per-RI utilization from Cost Explorer, scoped to EC2 RIs in region.
func (*RecommendationsClientAdapter) GetRecommendations ¶
func (r *RecommendationsClientAdapter) GetRecommendations(ctx context.Context, params *common.RecommendationParams) ([]common.Recommendation, error)
GetRecommendations gets recommendations with filtering.
func (*RecommendationsClientAdapter) GetRecommendationsForService ¶
func (r *RecommendationsClientAdapter) GetRecommendationsForService(ctx context.Context, service common.ServiceType) ([]common.Recommendation, error)
GetRecommendationsForService gets recommendations for a specific service.
func (*RecommendationsClientAdapter) SetRecLookbackPeriod ¶
func (r *RecommendationsClientAdapter) SetRecLookbackPeriod(period string)
SetRecLookbackPeriod configures the LookbackPeriodInDays forwarded to GetReservationPurchaseRecommendation. Valid values: "7d", "30d", "60d".
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
offeringprice
Package offeringprice turns the price fields of an AWS reserved-capacity offering into the figures common.OfferingDetails reports.
|
Package offeringprice turns the price fields of an AWS reserved-capacity offering into the figures common.OfferingDetails reports. |
|
purchasecfg
Package purchasecfg provides a tightened AWS SDK config for purchase-path clients.
|
Package purchasecfg provides a tightened AWS SDK config for purchase-path clients. |
|
reservationstate
Package reservationstate classifies AWS reservation lifecycle states.
|
Package reservationstate classifies AWS reservation lifecycle states. |
|
tagging
Package tagging builds the shared CUDly tag set applied to AWS Reserved Instance-style commitments at purchase time.
|
Package tagging builds the shared CUDly tag set applied to AWS Reserved Instance-style commitments at purchase time. |
|
Package ladder implements ladder.LadderCapability for AWS: the read side (commitment listing, layer states, usage baseline) and the write side (layer purchases, buffer reshaping).
|
Package ladder implements ladder.LadderCapability for AWS: the read side (commitment listing, layer states, usage baseline) and the write side (layer purchases, buffer reshaping). |
|
Package recommendations provides AWS Cost Explorer recommendations client
|
Package recommendations provides AWS Cost Explorer recommendations client |
|
services
|
|
|
ec2
Package ec2 provides AWS EC2 Reserved Instances client
|
Package ec2 provides AWS EC2 Reserved Instances client |
|
elasticache
Package elasticache provides AWS ElastiCache Reserved Cache Nodes client
|
Package elasticache provides AWS ElastiCache Reserved Cache Nodes client |
|
memorydb
Package memorydb provides AWS MemoryDB Reserved Nodes client
|
Package memorydb provides AWS MemoryDB Reserved Nodes client |
|
opensearch
Package opensearch provides AWS OpenSearch Reserved Instances client
|
Package opensearch provides AWS OpenSearch Reserved Instances client |
|
rds
Package rds provides AWS RDS Reserved Instances client
|
Package rds provides AWS RDS Reserved Instances client |
|
redshift
Package redshift provides AWS Redshift Reserved Nodes client
|
Package redshift provides AWS Redshift Reserved Nodes client |
|
savingsplans
Package savingsplans provides AWS Savings Plans purchase client
|
Package savingsplans provides AWS Savings Plans purchase client |