airflow.providers.amazon.aws.hooks.eks¶
Interact with Amazon EKS, using the boto3 library.
Attributes¶
Classes¶
Contains the possible State values of an EKS Cluster. |
|
Contains the possible State values of an AWS Fargate profile. |
|
Contains the possible State values of an EKS Managed Nodegroup. |
|
Interact with Amazon Elastic Kubernetes Service (EKS). |
Module Contents¶
- airflow.providers.amazon.aws.hooks.eks.AUTHENTICATION_API_VERSION = 'client.authentication.k8s.io/v1'[source]¶
- class airflow.providers.amazon.aws.hooks.eks.ClusterStates(*args, **kwds)[source]¶
Bases:
enum.EnumContains the possible State values of an EKS Cluster.
- class airflow.providers.amazon.aws.hooks.eks.FargateProfileStates(*args, **kwds)[source]¶
Bases:
enum.EnumContains the possible State values of an AWS Fargate profile.
- class airflow.providers.amazon.aws.hooks.eks.NodegroupStates(*args, **kwds)[source]¶
Bases:
enum.EnumContains the possible State values of an EKS Managed Nodegroup.
- airflow.providers.amazon.aws.hooks.eks.COMMAND = Multiline-String[source]¶
Show Value
""" export PYTHON_OPERATORS_VIRTUAL_ENV_MODE=1 # Load credentials from secure file using (POSIX-compliant dot operator) . {credentials_file} # Redirect stderr to a temporary file to prevent Python warnings, # deprecation notices, or other log output from contaminating stdout. # The token output must be the ONLY thing on stdout for bash token # parsing to work, but stderr should still be reported on failure. stderr_file=$(mktemp) trap 'rm -f "$stderr_file"' EXIT output=$({python_executable} -m airflow.providers.amazon.aws.utils.eks_get_token --cluster-name {eks_cluster_name} --sts-url '{sts_url}' {args} 2>"$stderr_file") status=$? # Clear environment variables after use (defense in depth) unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN if [ "$status" -ne 0 ]; then printf 'eks_get_token failed with exit code %s.' "$status" >&2 if [ -s "$stderr_file" ]; then printf ' Stderr was: ' >&2 cat "$stderr_file" >&2 fi exit "$status" fi # Keep only the token line even if a dependency logs to stdout. last_line=$(printf '%s\n' "$output" | tail -n 1) timestamp=${{last_line#expirationTimestamp: }} # drop the label timestamp=${{timestamp%%,*}} # keep up to the first comma token=${{last_line##*, token: }} # text after ", token: " # Validate that token was extracted — empty token means parsing failed # or eks_get_token produced unexpected output. Without this check, a # malformed ExecCredential is sent to the API server, resulting in a # 401 with an empty user identity in the audit logs. if [ -z "$token" ]; then printf 'Failed to extract token from eks_get_token output.' >&2 exit 1 fi json_string=$(printf '{{"kind": "ExecCredential","apiVersion": "{authentication_api_version}","spec": {{}},"status": {{"expirationTimestamp": "%s","token": "%s"}}}}' "$timestamp" "$token") echo $json_string """
- class airflow.providers.amazon.aws.hooks.eks.EksHook(*args, **kwargs)[source]¶
Bases:
airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHookInteract with Amazon Elastic Kubernetes Service (EKS).
Provide thin wrapper around
boto3.client("eks").Additional arguments (such as
aws_conn_id) may be specified and are passed down to the underlying AwsBaseHook.- create_cluster(name, roleArn, resourcesVpcConfig, **kwargs)[source]¶
Create an Amazon EKS control plane.
See also
- Parameters:
name (str) – The unique name to give to your Amazon EKS Cluster.
roleArn (str) – The Amazon Resource Name (ARN) of the IAM role that provides permissions for the Kubernetes control plane to make calls to AWS API operations on your behalf.
resourcesVpcConfig (dict) – The VPC configuration used by the cluster control plane.
- Returns:
Returns descriptive information about the created EKS Cluster.
- Return type:
- create_nodegroup(clusterName, nodegroupName, subnets, nodeRole, *, tags=None, **kwargs)[source]¶
Create an Amazon EKS managed node group for an Amazon EKS Cluster.
See also
- Parameters:
clusterName (str) – The name of the Amazon EKS cluster to create the EKS Managed Nodegroup in.
nodegroupName (str) – The unique name to give your managed nodegroup.
subnets (list[str]) – The subnets to use for the Auto Scaling group that is created for your nodegroup.
nodeRole (str | None) – The Amazon Resource Name (ARN) of the IAM role to associate with your nodegroup.
tags (dict | None) – Optional tags to apply to your nodegroup.
- Returns:
Returns descriptive information about the created EKS Managed Nodegroup.
- Return type:
- create_fargate_profile(clusterName, fargateProfileName, podExecutionRoleArn, selectors, **kwargs)[source]¶
Create an AWS Fargate profile for an Amazon EKS cluster.
See also
- Parameters:
clusterName (str) – The name of the Amazon EKS cluster to apply the Fargate profile to.
fargateProfileName (str | None) – The name of the Fargate profile.
podExecutionRoleArn (str | None) – The Amazon Resource Name (ARN) of the pod execution role to use for pods that match the selectors in the Fargate profile.
selectors (list) – The selectors to match for pods to use this Fargate profile.
- Returns:
Returns descriptive information about the created Fargate profile.
- Return type:
- delete_nodegroup(clusterName, nodegroupName)[source]¶
Delete an Amazon EKS managed node group from a specified cluster.
See also
- delete_fargate_profile(clusterName, fargateProfileName)[source]¶
Delete an AWS Fargate profile from a specified Amazon EKS cluster.
See also
- describe_cluster(name, verbose=False)[source]¶
Return descriptive information about an Amazon EKS Cluster.
See also
- describe_nodegroup(clusterName, nodegroupName, verbose=False)[source]¶
Return descriptive information about an Amazon EKS managed node group.
See also
- Parameters:
- Returns:
Returns descriptive information about a specific EKS Nodegroup.
- Return type:
- describe_fargate_profile(clusterName, fargateProfileName, verbose=False)[source]¶
Return descriptive information about an AWS Fargate profile.
- Parameters:
- Returns:
Returns descriptive information about an AWS Fargate profile.
- Return type:
- get_cluster_state(clusterName)[source]¶
Return the current status of a given Amazon EKS Cluster.
See also
- Parameters:
clusterName (str) – The name of the cluster to check.
- Returns:
Returns the current status of a given Amazon EKS Cluster.
- Return type:
- get_fargate_profile_state(clusterName, fargateProfileName)[source]¶
Return the current status of a given AWS Fargate profile.
- Parameters:
- Returns:
Returns the current status of a given AWS Fargate profile.
- Return type:
- get_nodegroup_state(clusterName, nodegroupName)[source]¶
Return the current status of a given Amazon EKS managed node group.
See also
- Parameters:
- Returns:
Returns the current status of a given Amazon EKS Nodegroup.
- Return type:
- list_nodegroups(clusterName, verbose=False)[source]¶
List all Amazon EKS managed node groups associated with the specified cluster.
See also
- list_fargate_profiles(clusterName, verbose=False)[source]¶
List all AWS Fargate profiles associated with the specified cluster.
See also
- generate_config_file_with_credentials(eks_cluster_name, pod_namespace)[source]¶
Create temporary kubeconfig and credential files using this hook’s AWS session.
Both files remain available until the context exits and are then removed, including when the caller raises an exception. The credential file can be refreshed in place while the context is active without regenerating the kubeconfig.