ServiceAccount
- class aws_cdk.aws_eks_v2.ServiceAccount(scope, id, *, cluster, annotations=None, identity_type=None, labels=None, name=None, namespace=None, overwrite_service_account=None, removal_policy=None)
Bases:
ConstructService Account.
- ExampleMetadata:
infused
Example:
import aws_cdk.aws_s3 as s3 # or create a new one using an existing issuer url # issuer_url: str from aws_cdk.lambda_layer_kubectl_v34 import KubectlV34Layer # you can import an existing provider provider = eks.OidcProviderNative.from_oidc_provider_arn(self, "Provider", "arn:aws:iam::123456:oidc-provider/oidc.eks.eu-west-1.amazonaws.com/id/AB123456ABC") provider2 = eks.OidcProviderNative(self, "Provider", url=issuer_url ) cluster = eks.Cluster.from_cluster_attributes(self, "MyCluster", cluster_name="Cluster", open_id_connect_provider=provider, kubectl_provider_options=eks.KubectlProviderOptions( kubectl_layer=KubectlV34Layer(self, "kubectl") ) ) service_account = cluster.add_service_account("MyServiceAccount") bucket = s3.Bucket(self, "Bucket") bucket.grant_read_write(service_account)
- Parameters:
scope (
Construct)id (
str)cluster (
ICluster) – The cluster to apply the patch to.annotations (
Optional[Mapping[str,str]]) – Additional annotations of the service account. Default: - no additional annotationsidentity_type (
Optional[IdentityType]) – The identity type to use for the service account. Default: IdentityType.IRSAlabels (
Optional[Mapping[str,str]]) – Additional labels of the service account. Default: - no additional labelsname (
Optional[str]) – The name of the service account. The name of a ServiceAccount object must be a valid DNS subdomain name. https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/ Default: - If no name is given, it will use the id of the resource.namespace (
Optional[str]) – The namespace of the service account. All namespace names must be valid RFC 1123 DNS labels. https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#namespaces-and-dns Default: “default”overwrite_service_account (
Optional[bool]) – Overwrite existing service account. If this is set, we will usekubectl applyinstead ofkubectl createwhen the service account is created. Otherwise, if there is already a service account in the cluster with the same name, the operation will fail. Default: falseremoval_policy (
Optional[RemovalPolicy]) – The removal policy applied to the service account resources. The removal policy controls what happens to the resources if they stop being managed by CloudFormation. This can happen in one of three situations: - The resource is removed from the template, so CloudFormation stops managing it - A change to the resource is made that requires it to be replaced, so CloudFormation stops managing it - The stack is deleted, so CloudFormation stops managing all resources in it Default: RemovalPolicy.DESTROY
Methods
- add_to_policy(statement)
(deprecated) Add to the policy of this principal.
- Parameters:
statement (
PolicyStatement)- Deprecated:
use
addToPrincipalPolicy()- Stability:
deprecated
- Return type:
bool
- add_to_principal_policy(statement)
Add to the policy of this principal.
- Parameters:
statement (
PolicyStatement)- Return type:
- to_string()
Returns a string representation of this construct.
- Return type:
str
- with_(*mixins)
Applies one or more mixins to this construct.
Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple
with()calls if subsequent mixins should apply to added constructs.- Parameters:
mixins (
IMixin) – The mixins to apply.- Return type:
- Returns:
This construct for chaining
Attributes
- assume_role_action
When this Principal is used in an AssumeRole policy, the action to use.
- grant_principal
The principal to grant permissions to.
- node
The tree node.
- policy_fragment
Return the policy fragment that identifies this principal in a Policy.
- role
The role which is linked to the service account.
- service_account_name
The name of the service account.
- service_account_namespace
The namespace where the service account is located in.
Static Methods
- classmethod is_construct(x)
Checks if
xis a construct.Use this method instead of
instanceofto properly detectConstructinstances, even when the construct library is symlinked.Explanation: in JavaScript, multiple copies of the
constructslibrary on disk are seen as independent, completely different libraries. As a consequence, the classConstructin each copy of theconstructslibrary is seen as a different class, and an instance of one class will not test asinstanceofthe other class.npm installwill not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of theconstructslibrary can be accidentally installed, andinstanceofwill behave unpredictably. It is safest to avoid usinginstanceof, and using this type-testing method instead.- Parameters:
x (
Any) – Any object.- Return type:
bool- Returns:
true if
xis an object created from a class which extendsConstruct.