Skip to content
v2.273.0

ServiceAccount ​

Service Account.

Example ​

ts
declare const cluster: eks.Cluster;

new eks.ServiceAccount(this, 'ServiceAccount', {
  cluster,
  name: 'test-sa',
  namespace: 'default',
  identityType: eks.IdentityType.POD_IDENTITY,
});
python
# cluster: eks.Cluster


eks.ServiceAccount(self, "ServiceAccount",
    cluster=cluster,
    name="test-sa",
    namespace="default",
    identity_type=eks.IdentityType.POD_IDENTITY
)
java
Cluster cluster;


ServiceAccount.Builder.create(this, "ServiceAccount")
        .cluster(cluster)
        .name("test-sa")
        .namespace("default")
        .identityType(IdentityType.POD_IDENTITY)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
Cluster cluster;


new ServiceAccount(this, "ServiceAccount", new ServiceAccountProps {
    Cluster = cluster,
    Name = "test-sa",
    Namespace = "default",
    IdentityType = IdentityType.POD_IDENTITY
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var cluster Cluster


eks.NewServiceAccount(this, jsii.String("ServiceAccount"), &ServiceAccountProps{
	Cluster: Cluster,
	Name: jsii.String("test-sa"),
	Namespace: jsii.String("default"),
	IdentityType: eks.IdentityType_POD_IDENTITY,
})

Initializer ​

ts
new ServiceAccount(scope: Construct, id: string, props: ServiceAccountProps)
python
ServiceAccount(scope: Construct, id: str, props: ServiceAccountProps)
java
new ServiceAccount(Construct scope, String id, ServiceAccountProps props)
csharp
new ServiceAccount(Construct scope, string id, ServiceAccountProps props)
go
NewServiceAccount(Scope Construct, Id *string, Props ServiceAccountProps)

Construct Props ​

annotations{ [key: string]: string }annotationstyping.Mapping[str, str]annotationsMap<String, String>AnnotationsIDictionary<string, string>Annotations*map[string]*string= no additional annotations#
Additional annotations of the service account.
clusterIClusterclusterIClusterclusterIClusterClusterIClusterClusterIClusterrequired#
The cluster to apply the patch to.
identityTypeIdentityTypeidentity_typeIdentityTypeidentityTypeIdentityTypeIdentityTypeIdentityTypeIdentityTypeIdentityType= IdentityType.IRSA#
The identity type to use for the service account.
labels{ [key: string]: string }labelstyping.Mapping[str, str]labelsMap<String, String>LabelsIDictionary<string, string>Labels*map[string]*string= no additional labels#
Additional labels of the service account.
namestringnamestrnameStringNamestringName*string= If no name is given, it will use…#
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

Default: If no name is given, it will use the id of the resource.

namespacestringnamespacestrnamespaceStringNamespacestringNamespace*string= "default"#
The namespace of the service account.
overwriteServiceAccountbooleanoverwrite_service_accountbooloverwriteServiceAccountBooleanOverwriteServiceAccountboolOverwriteServiceAccount*bool= false#
Overwrite existing service account.

If this is set, we will use kubectl apply instead of kubectl create when the service account is created. Otherwise, if there is already a service account in the cluster with the same name, the operation will fail.

removalPolicyRemovalPolicyremoval_policyRemovalPolicyremovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicy= RemovalPolicy.DESTROY#
The removal policy applied to the service account resources.
notes

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

Properties ​

assumeRoleActionstringassume_role_actionstrassumeRoleActionStringAssumeRoleActionstringAssumeRoleAction*stringrequired#
When this Principal is used in an AssumeRole policy, the action to use.
grantPrincipalIPrincipalgrant_principalIPrincipalgrantPrincipalIPrincipalGrantPrincipalIPrincipalGrantPrincipalIPrincipalrequired#
The principal to grant permissions to.
nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
policyFragmentPrincipalPolicyFragmentpolicy_fragmentPrincipalPolicyFragmentpolicyFragmentPrincipalPolicyFragmentPolicyFragmentPrincipalPolicyFragmentPolicyFragmentPrincipalPolicyFragmentrequired#
Return the policy fragment that identifies this principal in a Policy.
roleIRoleroleIRoleroleIRoleRoleIRoleRoleIRolerequired#
The role which is linked to the service account.
serviceAccountNamestringservice_account_namestrserviceAccountNameStringServiceAccountNamestringServiceAccountName*stringrequired#
The name of the service account.
serviceAccountNamespacestringservice_account_namespacestrserviceAccountNamespaceStringServiceAccountNamespacestringServiceAccountNamespace*stringrequired#
The namespace where the service account is located in.

Methods ​

addToPrincipalPolicy(statement: PolicyStatement): AddToPrincipalPolicyResultdef add_to_principal_policy(self, statement: PolicyStatement) -> AddToPrincipalPolicyResultpublic AddToPrincipalPolicyResult addToPrincipalPolicy(PolicyStatement statement)public AddToPrincipalPolicyResult AddToPrincipalPolicy(PolicyStatement statement)func AddToPrincipalPolicy(Statement PolicyStatement) AddToPrincipalPolicyResult#
Add to the policy of this principal.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
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.

1 parameter · returns

Parameters

  • mixinsmixinsmixinsmixinsMixins — The mixins to apply.

Returns: This construct for chaining