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: CloudProvider

Amazon Web Services.

Parameters:

allow_in_tests (bool) – Allow it to reach AWS in the unit tests, e.g. in a test tagged INFRASTRUCTURE.

__init__(allow_in_tests=False, **kwargs)[source]
property account_id: str | None

The AWS account id of the caller identity, or None if it is not authenticated.

property base: AWSBase

The low-level AWS helper that authenticates, created when it is first used.

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.

property eks: AWSEks

The low-level EKS helper.

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. a ClientError, 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:

ClusterHealth

Returns:

The cluster’s health. A part that could not be read is named in its errors.

Raises:
get_kubernetes_cluster_info()[source]

Describe the EKS cluster, e.g. its status and versions, for the status API.

Return type:

dict[str, Any]

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:

dict[str, list[DiscoveredResource]]

get_kubernetes_token()[source]

Create a bearer token for the EKS cluster, which kubectl uses instead of aws eks get-token.

Return type:

tuple[str, float] | None

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:

None

property sdk_version: str

The version of boto3.

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.

update_kubeconfig()[source]

Write the EKS cluster’s kubeconfig, for kubectl.

Return type:

bool

Returns:

True if it was written, False if AWS is not ready or it could not be written.

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: DNSService

AWS Route53, as the platform’s DNS.

Parameters:

provider (AWSProvider) – The AWS provider, which authenticates with AWS.

__init__(provider, **kwargs)[source]
property ready: bool

Whether the AWS provider is ready, i.e. authenticated 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:

DNSRecord

smarter.apps.infrastructure.providers.aws.dns.to_record_set(record)[source]

A DNSRecord as a Route53 record set.

TXT values are quoted, as Route53 requires.

Return type:

dict[str, Any]

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:
  • hosted_zone (dict[str, Any]) – The hosted zone, as Route53 returns it, with its Id and Name.

  • delegation_set (dict[str, Any] | None) – The zone’s delegation set, whose NameServers are the zone’s name servers, or None, for a zone without name servers.

Return type:

DNSZone

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: CertificateService

AWS 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.

__init__(provider, dns, **kwargs)[source]
property acm: AWSCertificateManager

The low-level ACM helper, created when it is first used.

property ready: bool

Whether the AWS provider is ready, i.e. authenticated with AWS.

smarter.apps.infrastructure.providers.aws.certificates.to_certificate(description)[source]

An ACM certificate’s description as a Certificate.

Return type:

Certificate