There are more AWS SDK examples available in the AWS Doc SDK Examples
Amazon EKS examples using AWS CLI
The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with Amazon EKS.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use associate-access-policy.
- AWS CLI
-
To associate an access policy and its scope to the access entry of the cluster
The following
associate-access-policyassociates an access policy and its scope to the access entry of the specified cluster.aws eks associate-access-policy \ --cluster-nameeks-customer\ --principal-arnarn:aws:iam::111122223333:role/Admin\ --policy-arnarn:aws:eks::aws:cluster-access-policy/AmazonEKSEditPolicy\ --access-scopetype=namespace,namespaces=defaultOutput:
{ "clusterName": "eks-customer", "principalArn": "arn:aws:iam::111122223333:role/Admin", "associatedAccessPolicy": { "policyArn": "arn:aws:eks::aws:cluster-access-policy/AmazonEKSEditPolicy", "accessScope": { "type": "namespace", "namespaces": [ "default" ] }, "associatedAt": "2025-05-24T15:59:51.981000-05:00", "modifiedAt": "2025-05-24T15:59:51.981000-05:00" } }For more information, see Associate access policies with access entries in the Amazon EKS User Guide.
-
For API details, see AssociateAccessPolicy
in AWS CLI Command Reference.
-
The following code example shows how to use associate-encryption-config.
- AWS CLI
-
To associates an encryption configuration to an existing cluster
The following
associate-encryption-configexample enable's encryption on an existing EKS clusters that do not already have encryption enabled.aws eks associate-encryption-config \ --cluster-namemy-eks-cluster\ --encryption-config '[{"resources":["secrets"],"provider":{"keyArn":"arn:aws:kms:region-code:account:key/key"}}]'Output:
{ "update": { "id": "3141b835-8103-423a-8e68-12c2521ffa4d", "status": "InProgress", "type": "AssociateEncryptionConfig", "params": [ { "type": "EncryptionConfig", "value": "[{\"resources\":[\"secrets\"],\"provider\":{\"keyArn\":\"arn:aws:kms:region-code:account:key/key\"}}]" } ], "createdAt": "2024-03-14T11:01:26.297000-04:00", "errors": [] } }For more information, see Enabling secret encryption on an existing cluster in the Amazon EKS User Guide.
-
For API details, see AssociateEncryptionConfig
in AWS CLI Command Reference.
-
The following code example shows how to use associate-identity-provider-config.
- AWS CLI
-
Associate identity provider to your Amazon EKS Cluster
The following
associate-identity-provider-configexample associates an identity provider to your Amazon EKS Cluster.aws eks associate-identity-provider-config \ --cluster-namemy-eks-cluster\ --oidc 'identityProviderConfigName=my-identity-provider,issuerUrl=https://oidc.eks.us-east-2.amazonaws.com/id/38D6A4619A0A69E342B113ED7F1A7652,clientId=kubernetes,usernameClaim=email,usernamePrefix=my-username-prefix,groupsClaim=my-claim,groupsPrefix=my-groups-prefix,requiredClaims={Claim1=value1,Claim2=value2}' \ --tagsenv=devOutput:
{ "update": { "id": "8c6c1bef-61fe-42ac-a242-89412387b8e7", "status": "InProgress", "type": "AssociateIdentityProviderConfig", "params": [ { "type": "IdentityProviderConfig", "value": "[{\"type\":\"oidc\",\"name\":\"my-identity-provider\"}]" } ], "createdAt": "2024-04-11T13:46:49.648000-04:00", "errors": [] }, "tags": { "env": "dev" } }For more information, see Authenticate users for your cluster from an OpenID Connect identity provider - Associate an OIDC identity provider in the Amazon EKS User Guide.
-
For API details, see AssociateIdentityProviderConfig
in AWS CLI Command Reference.
-
The following code example shows how to use create-access-entry.
- AWS CLI
-
Example 1: To create the access entry for EKS cluster
The following
create-access-entryexample creates an access entry that allows an IAM principal to access the EKS cluster.aws eks create-access-entry \ --cluster-nameeks-customer\ --principal-arnarn:aws:iam::111122223333:user/eks-userOutput:
{ "accessEntry": { "clusterName": "eks-customer", "principalArn": "arn:aws:iam::111122223333:user/eks-user", "kubernetesGroups": [], "accessEntryArn": "arn:aws:eks:us-west-2:111122223333:access-entry/eks-customer/user/111122223333/eks-user/a1b2c3d4-5678-90ab-cdef-a6506e3d36p0", "createdAt": "2025-04-14T22:45:48.097000-05:00", "modifiedAt": "2025-04-14T22:45:48.097000-05:00", "tags": {}, "username": "arn:aws:iam::111122223333:user/eks-user", "type": "STANDARD" } }For more information, see Create access entries in the Amazon EKS User Guide.
Example 2: To create the access entry for EKS cluster by specifying the type of access entry
The following
create-access-entryexample creates an access entry of typeEC2_LINUXin the EKS cluster. By default, a typeSTANDARDaccess entry is created. Apart from the default, if we specify any other access entry types, an IAM role ARN needs to be passed in the CLI.aws eks create-access-entry \ --cluster-nameeks-customer\ --principal-arnarn:aws:iam::111122223333:role/admin-test-ip\ --typeEC2_LINUXOutput:
{ "accessEntry": { "clusterName": "eks-customer", "principalArn": "arn:aws:iam::111122223333:role/admin-test-ip", "kubernetesGroups": [ "system:nodes" ], "accessEntryArn": "arn:aws:eks:us-west-2:111122223333:access-entry/eks-customer/role/111122223333/admin-test-ip/accb5418-f493-f390-3e6e-c3f19f725fcp", "createdAt": "2025-05-06T19:42:45.453000-05:00", "modifiedAt": "2025-05-06T19:42:45.453000-05:00", "tags": {}, "username": "system:node:{{EC2PrivateDNSName}}", "type": "EC2_LINUX" } }For more information, see Create access entries in the Amazon EKS User Guide.
-
For API details, see CreateAccessEntry
in AWS CLI Command Reference.
-
The following code example shows how to use create-addon.
- AWS CLI
-
Example 1: To create an Amazon EKS add-on with default compatible version for the respective EKS cluster version
The following
create-addonexample command creates an Amazon EKS add-on with default compatible version for the respective EKS cluster version.aws eks create-addon \ --cluster-namemy-eks-cluster\ --addon-namemy-eks-addon\ --service-account-role-arnarn:aws:iam::111122223333:role/role-nameOutput:
{ "addon": { "addonName": "my-eks-addon", "clusterName": "my-eks-cluster", "status": "CREATING", "addonVersion": "v1.15.1-eksbuild.1", "health": { "issues": [] }, "addonArn": "arn:aws:eks:us-east-2:111122223333:addon/my-eks-cluster/my-eks-addon/1ec71ee1-b9c2-8915-4e17-e8be0a55a149", "createdAt": "2024-03-14T12:20:03.264000-04:00", "modifiedAt": "2024-03-14T12:20:03.283000-04:00", "serviceAccountRoleArn": "arn:aws:iam::111122223333:role/role-name", "tags": {} } }For more information, see Managing Amazon EKS add-ons - Creating an add-on in the Amazon EKS User Guide.
Example 2: To create an Amazon EKS add-on with specific add-on version
The following
create-addonexample command creates an Amazon EKS add-on with specific add-on version.aws eks create-addon \ --cluster-namemy-eks-cluster\ --addon-namemy-eks-addon\ --service-account-role-arnarn:aws:iam::111122223333:role/role-name\ --addon-versionv1.16.4-eksbuild.2Output:
{ "addon": { "addonName": "my-eks-addon", "clusterName": "my-eks-cluster", "status": "CREATING", "addonVersion": "v1.16.4-eksbuild.2", "health": { "issues": [] }, "addonArn": "arn:aws:eks:us-east-2:111122223333:addon/my-eks-cluster/my-eks-addon/34c71ee6-7738-6c8b-c6bd-3921a176b5ff", "createdAt": "2024-03-14T12:30:24.507000-04:00", "modifiedAt": "2024-03-14T12:30:24.521000-04:00", "serviceAccountRoleArn": "arn:aws:iam::111122223333:role/role-name", "tags": {} } }For more information, see Managing Amazon EKS add-ons - Creating an add-on in the Amazon EKS User Guide.
Example 3: To create an Amazon EKS add-on with custom configuration values and resolve conflicts details
The following
create-addonexample command creates an Amazon EKS add-on with custom configuration values and resolves conflicts details.aws eks create-addon \ --cluster-namemy-eks-cluster\ --addon-namemy-eks-addon\ --service-account-role-arnarn:aws:iam::111122223333:role/role-name\ --addon-versionv1.16.4-eksbuild.2\ --configuration-values '{"resources":{"limits":{"cpu":"100m"}}}' \ --resolve-conflictsOVERWRITEOutput:
{ "addon": { "addonName": "my-eks-addon", "clusterName": "my-eks-cluster", "status": "CREATING", "addonVersion": "v1.16.4-eksbuild.2", "health": { "issues": [] }, "addonArn": "arn:aws:eks:us-east-2:111122223333:addon/my-eks-cluster/my-eks-addon/a6c71ee9-0304-9237-1be8-25af1b0f1ffb", "createdAt": "2024-03-14T12:35:58.313000-04:00", "modifiedAt": "2024-03-14T12:35:58.327000-04:00", "serviceAccountRoleArn": "arn:aws:iam::111122223333:role/role-name", "tags": {}, "configurationValues": "{\"resources\":{\"limits\":{\"cpu\":\"100m\"}}}" } }For more information, see Managing Amazon EKS add-ons - Creating an add-on in the Amazon EKS User Guide.
Example 4: To create an Amazon EKS add-on with custom JSON configuration values file
The following
create-addonexample command creates an Amazon EKS add-on with custom configuration values and resolve conflicts details.aws eks create-addon \ --cluster-namemy-eks-cluster\ --addon-namemy-eks-addon\ --service-account-role-arnarn:aws:iam::111122223333:role/role-name\ --addon-versionv1.16.4-eksbuild.2\ --configuration-values 'file://configuration-values.json' \ --resolve-conflictsOVERWRITE\ --tags '{"eks-addon-key-1": "value-1" , "eks-addon-key-2": "value-2"}'Contents of
configuration-values.json:{ "resources": { "limits": { "cpu": "150m" } }, "env": { "AWS_VPC_K8S_CNI_LOGLEVEL": "ERROR" } }Output:
{ "addon": { "addonName": "my-eks-addon", "clusterName": "my-eks-cluster", "status": "CREATING", "addonVersion": "v1.16.4-eksbuild.2", "health": { "issues": [] }, "addonArn": "arn:aws:eks:us-east-2:111122223333:addon/my-eks-cluster/my-eks-addon/d8c71ef8-fbd8-07d0-fb32-6a7be19ececd", "createdAt": "2024-03-14T13:10:51.763000-04:00", "modifiedAt": "2024-03-14T13:10:51.777000-04:00", "serviceAccountRoleArn": "arn:aws:iam::111122223333:role/role-name", "tags": { "eks-addon-key-1": "value-1", "eks-addon-key-2": "value-2" }, "configurationValues": "{\n \"resources\": {\n \"limits\": {\n \"cpu\": \"150m\"\n }\n },\n \"env\": {\n \"AWS_VPC_K8S_CNI_LOGLEVEL\": \"ERROR\"\n }\n}" } }For more information, see Managing Amazon EKS add-ons - Creating an add-on in the Amazon EKS User Guide.
Example 5: To create an Amazon EKS add-on with custom YAML configuration values file
The following
create-addonexample command creates an Amazon EKS add-on with custom configuration values and resolve conflicts details.aws eks create-addon \ --cluster-namemy-eks-cluster\ --addon-namemy-eks-addon\ --service-account-role-arnarn:aws:iam::111122223333:role/role-name\ --addon-versionv1.16.4-eksbuild.2\ --configuration-values 'file://configuration-values.yaml' \ --resolve-conflictsOVERWRITE\ --tags '{"eks-addon-key-1": "value-1" , "eks-addon-key-2": "value-2"}'Contents of
configuration-values.yaml:resources: limits: cpu: '100m' env: AWS_VPC_K8S_CNI_LOGLEVEL: 'DEBUG'Output:
{ "addon": { "addonName": "my-eks-addon", "clusterName": "my-eks-cluster", "status": "CREATING", "addonVersion": "v1.16.4-eksbuild.2", "health": { "issues": [] }, "addonArn": "arn:aws:eks:us-east-2:111122223333:addon/my-eks-cluster/my-eks-addon/d4c71efb-3909-6f36-a548-402cd4b5d59e", "createdAt": "2024-03-14T13:15:45.220000-04:00", "modifiedAt": "2024-03-14T13:15:45.237000-04:00", "serviceAccountRoleArn": "arn:aws:iam::111122223333:role/role-name", "tags": { "eks-addon-key-3": "value-3", "eks-addon-key-4": "value-4" }, "configurationValues": "resources:\n limits:\n cpu: '100m'\nenv:\n AWS_VPC_K8S_CNI_LOGLEVEL: 'INFO'" } }For more information, see Managing Amazon EKS add-ons - Creating an add-on in the Amazon EKS User Guide.
-
For API details, see CreateAddon
in AWS CLI Command Reference.
-
The following code example shows how to use create-cluster.
- AWS CLI
-
To create a new cluster
This example command creates a cluster named
prodin your default region.Command:
aws eks create-cluster --nameprod\ --role-arnarn:aws:iam::012345678910:role/eks-service-role-AWSServiceRoleForAmazonEKS-J7ONKE3BQ4PI\ --resources-vpc-configsubnetIds=subnet-6782e71e,subnet-e7e761ac,securityGroupIds=sg-6979fe18Output:
{ "cluster": { "name": "prod", "arn": "arn:aws:eks:us-west-2:012345678910:cluster/prod", "createdAt": 1527808069.147, "version": "1.10", "roleArn": "arn:aws:iam::012345678910:role/eks-service-role-AWSServiceRoleForAmazonEKS-J7ONKE3BQ4PI", "resourcesVpcConfig": { "subnetIds": [ "subnet-6782e71e", "subnet-e7e761ac" ], "securityGroupIds": [ "sg-6979fe18" ], "vpcId": "vpc-950809ec" }, "status": "CREATING", "certificateAuthority": {} } }To create a new cluster with private endpoint access and logging enabled
This example command creates a cluster named
examplein your default region with public endpoint access disabled, private endpoint access enabled, and all logging types enabled.Command:
aws eks create-cluster --nameexample--kubernetes-version1.12\ --role-arnarn:aws:iam::012345678910:role/example-cluster-ServiceRole-1XWBQWYSFRE2Q\ --resources-vpc-configsubnetIds=subnet-0a188dccd2f9a632f,subnet-09290d93da4278664,subnet-0f21dd86e0e91134a,subnet-0173dead68481a583,subnet-051f70a57ed6fcab6,subnet-01322339c5c7de9b4,securityGroupIds=sg-0c5b580845a031c10,endpointPublicAccess=false,endpointPrivateAccess=true\ --logging '{"clusterLogging":[{"types":["api","audit","authenticator","controllerManager","scheduler"],"enabled":true}]}'Output:
{ "cluster": { "name": "example", "arn": "arn:aws:eks:us-west-2:012345678910:cluster/example", "createdAt": 1565804921.901, "version": "1.12", "roleArn": "arn:aws:iam::012345678910:role/example-cluster-ServiceRole-1XWBQWYSFRE2Q", "resourcesVpcConfig": { "subnetIds": [ "subnet-0a188dccd2f9a632f", "subnet-09290d93da4278664", "subnet-0f21dd86e0e91134a", "subnet-0173dead68481a583", "subnet-051f70a57ed6fcab6", "subnet-01322339c5c7de9b4" ], "securityGroupIds": [ "sg-0c5b580845a031c10" ], "vpcId": "vpc-0f622c01f68d4afec", "endpointPublicAccess": false, "endpointPrivateAccess": true }, "logging": { "clusterLogging": [ { "types": [ "api", "audit", "authenticator", "controllerManager", "scheduler" ], "enabled": true } ] }, "status": "CREATING", "certificateAuthority": {}, "platformVersion": "eks.3" } }-
For API details, see CreateCluster
in AWS CLI Command Reference.
-
The following code example shows how to use create-fargate-profile.
- AWS CLI
-
Example 1: Create EKS Fargate Profile for a selector with a namespace
The following
create-fargate-profileexample creates an EKS Fargate Profile for a selector with a namespace.aws eks create-fargate-profile \ --cluster-namemy-eks-cluster\ --pod-execution-role-arnarn:aws:iam::111122223333:role/role-name\ --fargate-profile-namemy-fargate-profile\ --selectors '[{"namespace": "default"}]'Output:
{ "fargateProfile": { "fargateProfileName": "my-fargate-profile", "fargateProfileArn": "arn:aws:eks:us-east-2:111122223333:fargateprofile/my-eks-cluster/my-fargate-profile/a2c72bca-318e-abe8-8ed1-27c6d4892e9e", "clusterName": "my-eks-cluster", "createdAt": "2024-03-19T12:38:47.368000-04:00", "podExecutionRoleArn": "arn:aws:iam::111122223333:role/role-name", "subnets": [ "subnet-09d912bb63ef21b9a", "subnet-04ad87f71c6e5ab4d", "subnet-0e2907431c9988b72" ], "selectors": [ { "namespace": "default" } ], "status": "CREATING", "tags": {} } }For more information, see AWS Fargate profile - Creating a Fargate profile in the Amazon EKS User Guide.
Example 2: Create EKS Fargate Profile for a selector with a namespace and labels
The following
create-fargate-profileexample creates an EKS Fargate Profile for a selector with a namespace and labels.aws eks create-fargate-profile \ --cluster-namemy-eks-cluster\ --pod-execution-role-arnarn:aws:iam::111122223333:role/role-name\ --fargate-profile-namemy-fargate-profile\ --selectors '[{"namespace": "default", "labels": {"labelname1": "labelvalue1"}}]'Output:
{ "fargateProfile": { "fargateProfileName": "my-fargate-profile", "fargateProfileArn": "arn:aws:eks:us-east-2:111122223333:fargateprofile/my-eks-cluster/my-fargate-profile/88c72bc7-e8a4-fa34-44e4-2f1397224bb3", "clusterName": "my-eks-cluster", "createdAt": "2024-03-19T12:33:48.125000-04:00", "podExecutionRoleArn": "arn:aws:iam::111122223333:role/role-name", "subnets": [ "subnet-09d912bb63ef21b9a", "subnet-04ad87f71c6e5ab4d", "subnet-0e2907431c9988b72" ], "selectors": [ { "namespace": "default", "labels": { "labelname1": "labelvalue1" } } ], "status": "CREATING", "tags": {} } }For more information, see AWS Fargate profile - Creating a Fargate profile in the Amazon EKS User Guide.
Example 3: Create EKS Fargate Profile for a selector with a namespace and labels, along with IDs of subnets to launch a Pod into.
The following
create-fargate-profileexample create EKS Fargate Profile for a selector with a namespace and labels, along with IDs of subnets to launch a Pod into.aws eks create-fargate-profile \ --cluster-namemy-eks-cluster\ --pod-execution-role-arnarn:aws:iam::111122223333:role/role-name\ --fargate-profile-namemy-fargate-profile\ --selectors '[{"namespace": "default", "labels": {"labelname1": "labelvalue1"}}]' \ --subnets '["subnet-09d912bb63ef21b9a", "subnet-04ad87f71c6e5ab4d", "subnet-0e2907431c9988b72"]'Output:
{ "fargateProfile": { "fargateProfileName": "my-fargate-profile", "fargateProfileArn": "arn:aws:eks:us-east-2:111122223333:fargateprofile/my-eks-cluster/my-fargate-profile/e8c72bc8-e87b-5eb6-57cb-ed4fe57577e3", "clusterName": "my-eks-cluster", "createdAt": "2024-03-19T12:35:58.640000-04:00", "podExecutionRoleArn": "arn:aws:iam::111122223333:role/role-name", "subnets": [ "subnet-09d912bb63ef21b9a", "subnet-04ad87f71c6e5ab4d", "subnet-0e2907431c9988b72" ], "selectors": [ { "namespace": "default", "labels": { "labelname1": "labelvalue1" } } ], "status": "CREATING", "tags": {} } }For more information, see AWS Fargate profile - Creating a Fargate profile in the Amazon EKS User Guide.
Example 4: Create EKS Fargate Profile for a selector with multiple namespace and labels, along with IDs of subnets to launch a Pod into
The following
create-fargate-profileexample creates an EKS Fargate Profile for a selector with multiple namespace and labels, along with IDs of subnets to launch a Pod into.aws eks create-fargate-profile \ --cluster-namemy-eks-cluster\ --pod-execution-role-arnarn:aws:iam::111122223333:role/role-name\ --fargate-profile-namemy-fargate-profile\ --selectors '[{"namespace": "default1", "labels": {"labelname1": "labelvalue1", "labelname2": "labelvalue2"}}, {"namespace": "default2", "labels": {"labelname1": "labelvalue1", "labelname2": "labelvalue2"}}]' \ --subnets '["subnet-09d912bb63ef21b9a", "subnet-04ad87f71c6e5ab4d", "subnet-0e2907431c9988b72"]' \ --tags '{"eks-fargate-profile-key-1": "value-1" , "eks-fargate-profile-key-2": "value-2"}'Output:
{ "fargateProfile": { "fargateProfileName": "my-fargate-profile", "fargateProfileArn": "arn:aws:eks:us-east-2:111122223333:fargateprofile/my-eks-cluster/my-fargate-profile/4cc72bbf-b766-8ee6-8d29-e62748feb3cd", "clusterName": "my-eks-cluster", "createdAt": "2024-03-19T12:15:55.271000-04:00", "podExecutionRoleArn": "arn:aws:iam::111122223333:role/role-name", "subnets": [ "subnet-09d912bb63ef21b9a", "subnet-04ad87f71c6e5ab4d", "subnet-0e2907431c9988b72" ], "selectors": [ { "namespace": "default1", "labels": { "labelname2": "labelvalue2", "labelname1": "labelvalue1" } }, { "namespace": "default2", "labels": { "labelname2": "labelvalue2", "labelname1": "labelvalue1" } } ], "status": "CREATING", "tags": { "eks-fargate-profile-key-2": "value-2", "eks-fargate-profile-key-1": "value-1" } } }For more information, see AWS Fargate profile - Creating a Fargate profile in the Amazon EKS User Guide.
Example 5: Create EKS Fargate Profile with a wildcard selector for namespaces and labels, along with IDs of subnets to launch a Pod into
The following
create-fargate-profileexample creates an EKS Fargate Profile for a selector with multiple namespace and labels, along with IDs of subnets to launch a Pod into.aws eks create-fargate-profile \ --cluster-namemy-eks-cluster\ --pod-execution-role-arnarn:aws:iam::111122223333:role/role-name\ --fargate-profile-namemy-fargate-profile\ --selectors '[{"namespace": "prod*", "labels": {"labelname*?": "*value1"}}, {"namespace": "*dev*", "labels": {"labelname*?": "*value*"}}]' \ --subnets '["subnet-09d912bb63ef21b9a", "subnet-04ad87f71c6e5ab4d", "subnet-0e2907431c9988b72"]' \ --tags '{"eks-fargate-profile-key-1": "value-1" , "eks-fargate-profile-key-2": "value-2"}'Output:
{ "fargateProfile": { "fargateProfileName": "my-fargate-profile", "fargateProfileArn": "arn:aws:eks:us-east-2:111122223333:fargateprofile/my-eks-cluster/my-fargate-profile/e8c72bd6-5966-0bfe-b77b-1802893e5a6f", "clusterName": "my-eks-cluster", "createdAt": "2024-03-19T13:05:20.550000-04:00", "podExecutionRoleArn": "arn:aws:iam::111122223333:role/role-name", "subnets": [ "subnet-09d912bb63ef21b9a", "subnet-04ad87f71c6e5ab4d", "subnet-0e2907431c9988b72" ], "selectors": [ { "namespace": "prod*", "labels": { "labelname*?": "*value1" } }, { "namespace": "*dev*", "labels": { "labelname*?": "*value*" } } ], "status": "CREATING", "tags": { "eks-fargate-profile-key-2": "value-2", "eks-fargate-profile-key-1": "value-1" } } }For more information, see AWS Fargate profile - Creating a Fargate profile in the Amazon EKS User Guide.
-
For API details, see CreateFargateProfile
in AWS CLI Command Reference.
-
The following code example shows how to use create-nodegroup.
- AWS CLI
-
Example 1: Creates a managed node group for an Amazon EKS cluster
The following
create-nodegroupexample creates a managed node group for an Amazon EKS cluster.aws eks create-nodegroup \ --cluster-namemy-eks-cluster\ --nodegroup-namemy-eks-nodegroup\ --node-rolearn:aws:iam::111122223333:role/role-name\ --subnets"subnet-0e2907431c9988b72""subnet-04ad87f71c6e5ab4d""subnet-09d912bb63ef21b9a"\ --scaling-configminSize=1,maxSize=3,desiredSize=1\ --regionus-east-2Output:
{ "nodegroup": { "nodegroupName": "my-eks-nodegroup", "nodegroupArn": "arn:aws:eks:us-east-2:111122223333:nodegroup/my-eks-cluster/my-eks-nodegroup/bac7550f-b8b8-5fbb-4f3e-7502a931119e", "clusterName": "my-eks-cluster", "version": "1.26", "releaseVersion": "1.26.12-20240329", "createdAt": "2024-04-04T13:19:32.260000-04:00", "modifiedAt": "2024-04-04T13:19:32.260000-04:00", "status": "CREATING", "capacityType": "ON_DEMAND", "scalingConfig": { "minSize": 1, "maxSize": 3, "desiredSize": 1 }, "instanceTypes": [ "t3.medium" ], "subnets": [ "subnet-0e2907431c9988b72, subnet-04ad87f71c6e5ab4d, subnet-09d912bb63ef21b9a" ], "amiType": "AL2_x86_64", "nodeRole": "arn:aws:iam::111122223333:role/role-name", "diskSize": 20, "health": { "issues": [] }, "updateConfig": { "maxUnavailable": 1 }, "tags": {} } }For more information, see Creating a managed node group in the Amazon EKS User Guide.
Example 2: Creates a managed node group for an Amazon EKS cluster with custom instance-types and disk-size
The following
create-nodegroupexample creates a managed node group for an Amazon EKS cluster with custom instance-types and disk-size.aws eks create-nodegroup \ --cluster-namemy-eks-cluster\ --nodegroup-namemy-eks-nodegroup\ --node-rolearn:aws:iam::111122223333:role/role-name\ --subnets"subnet-0e2907431c9988b72""subnet-04ad87f71c6e5ab4d""subnet-09d912bb63ef21b9a"\ --scaling-configminSize=1,maxSize=3,desiredSize=1\ --capacity-typeON_DEMAND\ --instance-types 'm5.large' \ --disk-size50\ --regionus-east-2Output:
{ "nodegroup": { "nodegroupName": "my-eks-nodegroup", "nodegroupArn": "arn:aws:eks:us-east-2:111122223333:nodegroup/my-eks-cluster/my-eks-nodegroup/c0c7551b-e4f9-73d9-992c-a450fdb82322", "clusterName": "my-eks-cluster", "version": "1.26", "releaseVersion": "1.26.12-20240329", "createdAt": "2024-04-04T13:46:07.595000-04:00", "modifiedAt": "2024-04-04T13:46:07.595000-04:00", "status": "CREATING", "capacityType": "ON_DEMAND", "scalingConfig": { "minSize": 1, "maxSize": 3, "desiredSize": 1 }, "instanceTypes": [ "m5.large" ], "subnets": [ "subnet-0e2907431c9988b72", "subnet-04ad87f71c6e5ab4d", "subnet-09d912bb63ef21b9a" ], "amiType": "AL2_x86_64", "nodeRole": "arn:aws:iam::111122223333:role/role-name", "diskSize": 50, "health": { "issues": [] }, "updateConfig": { "maxUnavailable": 1 }, "tags": {} } }For more information, see Creating a managed node group in the Amazon EKS User Guide.
Example 3: Creates a managed node group for an Amazon EKS cluster with custom instance-types, disk-size, ami-type, capacity-type, update-config, labels, taints and tags.
The following
create-nodegroupexample creates a managed node group for an Amazon EKS cluster with custom instance-types, disk-size, ami-type, capacity-type, update-config, labels, taints and tags.aws eks create-nodegroup \ --cluster-namemy-eks-cluster\ --nodegroup-namemy-eks-nodegroup\ --node-rolearn:aws:iam::111122223333:role/role-name\ --subnets"subnet-0e2907431c9988b72""subnet-04ad87f71c6e5ab4d""subnet-09d912bb63ef21b9a"\ --scaling-configminSize=1,maxSize=5,desiredSize=4\ --instance-types 't3.large' \ --disk-size50\ --ami-typeAL2_x86_64\ --capacity-typeSPOT\ --update-configmaxUnavailable=2\ --labels '{"my-eks-nodegroup-label-1": "value-1" , "my-eks-nodegroup-label-2": "value-2"}' \ --taints '{"key": "taint-key-1" , "value": "taint-value-1", "effect": "NO_EXECUTE"}' \ --tags '{"my-eks-nodegroup-key-1": "value-1" , "my-eks-nodegroup-key-2": "value-2"}'Output:
{ "nodegroup": { "nodegroupName": "my-eks-nodegroup", "nodegroupArn": "arn:aws:eks:us-east-2:111122223333:nodegroup/my-eks-cluster/my-eks-nodegroup/88c75524-97af-0cb9-a9c5-7c0423ab5314", "clusterName": "my-eks-cluster", "version": "1.26", "releaseVersion": "1.26.12-20240329", "createdAt": "2024-04-04T14:05:07.940000-04:00", "modifiedAt": "2024-04-04T14:05:07.940000-04:00", "status": "CREATING", "capacityType": "SPOT", "scalingConfig": { "minSize": 1, "maxSize": 5, "desiredSize": 4 }, "instanceTypes": [ "t3.large" ], "subnets": [ "subnet-0e2907431c9988b72", "subnet-04ad87f71c6e5ab4d", "subnet-09d912bb63ef21b9a" ], "amiType": "AL2_x86_64", "nodeRole": "arn:aws:iam::111122223333:role/role-name", "labels": { "my-eks-nodegroup-label-2": "value-2", "my-eks-nodegroup-label-1": "value-1" }, "taints": [ { "key": "taint-key-1", "value": "taint-value-1", "effect": "NO_EXECUTE" } ], "diskSize": 50, "health": { "issues": [] }, "updateConfig": { "maxUnavailable": 2 }, "tags": { "my-eks-nodegroup-key-1": "value-1", "my-eks-nodegroup-key-2": "value-2" } } }For more information, see Creating a managed node group in the Amazon EKS User Guide.
-
For API details, see CreateNodegroup
in AWS CLI Command Reference.
-
The following code example shows how to use create-pod-identity-association.
- AWS CLI
-
Example 1: To create an EKS Pod Identity association in EKS cluster
The following
create-pod-identity-associationexample creates an EKS Pod Identity association between a service account in the EKS cluster and an IAM role.aws eks create-pod-identity-association \ --cluster-nameeks-customer\ --namespacedefault\ --service-accountdefault\ --role-arnarn:aws:iam::111122223333:role/my-roleOutput:
{ "association": { "clusterName": "eks-customer", "namespace": "default", "serviceAccount": "default", "roleArn": "arn:aws:iam::111122223333:role/my-role", "associationArn": "arn:aws:eks:us-west-2:111122223333:podidentityassociation/eks-customer/a-8mvwvh57cu74mgcst", "associationId": "a-8mvwvh57cu74mgcst", "tags": {}, "createdAt": "2025-05-24T19:40:13.961000-05:00", "modifiedAt": "2025-05-24T19:40:13.961000-05:00" } }For more information, see Learn how EKS Pod Identity grants pods access to AWS services in the Amazon EKS User Guide.