AWS Provider
The AWS cloud provider.
AWSProvider replaces smarter.common.helpers.aws_helpers.AWSInfrastructureConfig. It
authenticates with AWS, with smarter_settings’ AWS credentials, and implements:
DNS, with Route53:
Route53DNSService.TLS certificates, with ACM:
ACMCertificateService.private object storage, with S3:
S3StorageService.the Kubernetes cluster’s kubeconfig, description, add-ons and node groups, with EKS.
Of the AWS services that the old helpers wrapped, only these are used by the platform. API Gateway, DynamoDB, IAM, Lambda, RDS and Rekognition were not, and were removed.
In the unit tests, it refuses to reach AWS, unless allow_in_tests is True, because the
Smarter containers’ AWS credentials are real.
- class smarter.apps.infrastructure.providers.aws.provider.AWSProvider(allow_in_tests=False, **kwargs)[source]
Bases:
CloudProviderAmazon Web Services.
- Parameters:
allow_in_tests (
bool) – Allow it to reach AWS in the unit tests, e.g. in a test taggedINFRASTRUCTURE.
- property account_id: str | None
The AWS account id of the caller identity, or None if it is not authenticated.
- property certificates: ACMCertificateService
ACM, as the provider’s certificate service, created when it is first used.
- property dns: Route53DNSService
Route53, as the provider’s DNS service, created when it is first used.
- get_kubernetes_cluster_health()[source]
Describe the EKS cluster’s health: its control plane, node groups, add-ons and insights.
It delegates to
get_cluster_health(), and translates its errors, e.g. aClientError, into the service’s own exception, so that the caller never handles an AWS SDK exception.Side effects: read-only calls to the EKS api. Nothing is changed.
- Return type:
- Returns:
The cluster’s health. A part that could not be read is named in its
errors.- Raises:
InfrastructureNotReadyError – If AWS is not ready.
SmarterInfrastructureError – If the cluster itself cannot be described.
- get_kubernetes_cluster_info()[source]
Describe the EKS cluster, e.g. its status and versions, for the status API.
- Return type:
- Returns:
The cluster’s description.
- Raises:
InfrastructureNotReadyError – If AWS is not ready.
- get_kubernetes_cluster_resources()[source]
Return the EKS cluster, which is billed by the hour, its add-ons, and its managed node groups.
A node group is not billed: its nodes, EC2 instances, are, and the inventory finds them in the cluster. Nothing is returned if EKS cannot be described.
- Return type:
- get_kubernetes_token()[source]
Create a bearer token for the EKS cluster, which kubectl uses instead of
aws eks get-token.- Return type:
- Returns:
The token and when it expires, as a
time.time(), or None if AWS is not ready or the token could not be created, for kubectl to use its kubeconfig’s credentials.
- property identity: dict[str, Any] | None
The AWS caller identity, from STS, or None if AWS is not configured.
- name: str = 'aws'
The provider’s name, see
CloudProviders.
- property ready: bool
Whether the provider is authenticated with AWS.
Fetches the caller identity from STS, and records the authentication state, which sends a signal when it changes.
- require_live()[source]
Refuse to reach AWS from the unit tests, unless allowed.
- Raises:
InfrastructureConfigurationError – In the unit tests, unless allowed.
- Return type:
- property session: Session | None
The boto3 session, for AWS-specific backends that need clients of their own.
e.g.
EKSNodeGroupBackend.
- property storage: S3StorageService
S3, as the provider’s private object storage, created when it is first used.
The DNS service of AWS: Route53.
Route53DNSService implements the primitives of
DNSService with the low-level
AWSRoute53 helper, and
translates between Route53’s hosted zones and record sets and the provider-independent
DNSZone and
DNSRecord.
- class smarter.apps.infrastructure.providers.aws.dns.Route53DNSService(provider, **kwargs)[source]
Bases:
DNSServiceAWS Route53, as the platform’s DNS.
- Parameters:
provider (
AWSProvider) – The AWS provider, which authenticates with AWS.
- property route53: AWSRoute53
The low-level Route53 helper, created when it is first used.
- smarter.apps.infrastructure.providers.aws.dns.to_record(record_set)[source]
A Route53 record set as a
DNSRecord.TXT values are unquoted.
- Return type:
- smarter.apps.infrastructure.providers.aws.dns.to_record_set(record)[source]
A
DNSRecordas a Route53 record set.TXT values are quoted, as Route53 requires.
- smarter.apps.infrastructure.providers.aws.dns.to_zone(hosted_zone, delegation_set=None)[source]
A Route53 hosted zone, and optionally its delegation set, as a
DNSZone.- Parameters:
- Return type:
- Returns:
The zone.
The certificate service of AWS: AWS Certificate Manager (ACM).
ACMCertificateService implements the primitives of
CertificateService with the
low-level AWSCertificateManager
helper. A certificate’s id is its ARN.
- class smarter.apps.infrastructure.providers.aws.certificates.ACMCertificateService(provider, dns, **kwargs)[source]
Bases:
CertificateServiceAWS Certificate Manager, as the platform’s certificate authority.
- Parameters:
provider (
AWSProvider) – The AWS provider, which authenticates with AWS.dns (
DNSService) – The DNS service of the validation records.
- property acm: AWSCertificateManager
The low-level ACM helper, created when it is first used.