We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
aws eks get-token doesn't work with --profile
When going to use `aws --profile profilename eks get-token --cluster-name eksClusterName` I receive the following error `Unable to locate credentials. You can configure credentials by running "aws configure".`. However, when I set the ENVVAR of AWS_DEFAULT_PROFILE to the profile I want, the command works fine.

I verified other eks commands work fine with the --profile option. For example: `aws --profile profilename eks describe-cluster --name eksClusterName` works as expected.


aws --version                                             
aws-cli/1.16.160 Python/3.7.0 Darwin/18.2.0 botocore/1.12.150

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `awscli/customizations/eks/get_token.py`
Content:
```
1 # Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"). You
4 # may not use this file except in compliance with the License. A copy of
5 # the License is located at
6 #
7 # http://aws.amazon.com/apache2.0/
8 #
9 # or in the "license" file accompanying this file. This file is
10 # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11 # ANY KIND, either express or implied. See the License for the specific
12 # language governing permissions and limitations under the License.
13 import base64
14 import botocore
15 import json
16 
17 from botocore import session
18 from botocore.signers import RequestSigner
19 from botocore.model import ServiceId
20 
21 from awscli.customizations.commands import BasicCommand
22 from awscli.customizations.utils import uni_print
23 
24 AUTH_SERVICE = "sts"
25 AUTH_COMMAND = "GetCallerIdentity"
26 AUTH_API_VERSION = "2011-06-15"
27 AUTH_SIGNING_VERSION = "v4"
28 
29 # Presigned url timeout in seconds
30 URL_TIMEOUT = 60
31 
32 TOKEN_PREFIX = 'k8s-aws-v1.'
33 
34 CLUSTER_NAME_HEADER = 'x-k8s-aws-id'
35 
36 
37 class GetTokenCommand(BasicCommand):
38     NAME = 'get-token'
39 
40     DESCRIPTION = ("Get a token for authentication with an Amazon EKS cluster. "
41                    "This can be used as an alternative to the "
42                    "aws-iam-authenticator.")
43 
44     ARG_TABLE = [
45         {
46             'name': 'cluster-name',
47             'help_text': ("Specify the name of the Amazon EKS cluster to create a token for."),
48             'required': True
49         },
50         {
51             'name': 'role-arn',
52             'help_text': ("Assume this role for credentials when signing the token."),
53             'required': False
54         }
55     ]
56 
57     def _run_main(self, parsed_args, parsed_globals):
58         token_generator = TokenGenerator(parsed_globals.region)
59         token = token_generator.get_token(
60             parsed_args.cluster_name,
61             parsed_args.role_arn
62         )
63 
64         full_object = {
65             "kind": "ExecCredential",
66             "apiVersion": "client.authentication.k8s.io/v1alpha1",
67             "spec": {},
68             "status": {
69                 "token": token
70             }
71         }
72 
73         uni_print(json.dumps(full_object))
74         uni_print('\n')
75 
76 class TokenGenerator(object):
77     def __init__(self, region_name, session_handler=None):
78         if session_handler is None:
79             session_handler = SessionHandler()
80         self._session_handler = session_handler
81         self._region_name = region_name
82 
83     def get_token(self, cluster_name, role_arn):
84         """ Generate a presigned url token to pass to kubectl. """
85         url = self._get_presigned_url(cluster_name, role_arn)
86         token = TOKEN_PREFIX + base64.urlsafe_b64encode(url.encode('utf-8')).decode('utf-8').rstrip('=')
87         return token
88 
89     def _get_presigned_url(self, cluster_name, role_arn):
90         session = self._session_handler.get_session(
91             self._region_name,
92             role_arn
93         )
94 
95         if self._region_name is None:
96             self._region_name = session.get_config_variable('region')
97 
98         loader = botocore.loaders.create_loader()
99         data = loader.load_data("endpoints")
100         endpoint_resolver = botocore.regions.EndpointResolver(data)
101         endpoint = endpoint_resolver.construct_endpoint(
102             AUTH_SERVICE,
103             self._region_name
104         )
105         signer = RequestSigner(
106             ServiceId(AUTH_SERVICE),
107             self._region_name,
108             AUTH_SERVICE,
109             AUTH_SIGNING_VERSION,
110             session.get_credentials(),
111             session.get_component('event_emitter')
112         )
113         action_params='Action=' + AUTH_COMMAND + '&Version=' + AUTH_API_VERSION
114         params = {
115             'method': 'GET',
116             'url': 'https://' + endpoint["hostname"] + '/?' + action_params,
117             'body': {},
118             'headers': {CLUSTER_NAME_HEADER: cluster_name},
119             'context': {}
120         }
121 
122         url=signer.generate_presigned_url(
123             params,
124             region_name=endpoint["credentialScope"]["region"],
125             operation_name='',
126             expires_in=URL_TIMEOUT
127         )
128         return url
129 
130 class SessionHandler(object):
131     def get_session(self, region_name, role_arn):
132         """
133         Assumes the given role and returns a session object assuming said role.
134         """
135         session = botocore.session.get_session()
136         if region_name is not None:
137             session.set_config_variable('region', region_name)
138 
139         if role_arn is not None:
140             sts = session.create_client(AUTH_SERVICE, region_name=region_name)
141             credentials_dict = sts.assume_role(
142                 RoleArn=role_arn,
143                 RoleSessionName='EKSGetTokenAuth'
144             )['Credentials']
145 
146             session.set_credentials(credentials_dict['AccessKeyId'],
147                                     credentials_dict['SecretAccessKey'],
148                                     credentials_dict['SessionToken'])
149             return session
150         else:
151             return session
152
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/awscli/customizations/eks/get_token.py b/awscli/customizations/eks/get_token.py
--- a/awscli/customizations/eks/get_token.py
+++ b/awscli/customizations/eks/get_token.py
@@ -54,11 +54,13 @@
         }
     ]
 
-    def _run_main(self, parsed_args, parsed_globals):
-        token_generator = TokenGenerator(parsed_globals.region)
+    def _run_main(self, parsed_args, parsed_globals, token_generator=None):
+        if token_generator is None:
+            token_generator = TokenGenerator(self._session)
         token = token_generator.get_token(
             parsed_args.cluster_name,
-            parsed_args.role_arn
+            parsed_args.role_arn,
+            parsed_globals.region,
         )
 
         full_object = {
@@ -74,37 +76,34 @@
         uni_print('\n')
 
 class TokenGenerator(object):
-    def __init__(self, region_name, session_handler=None):
-        if session_handler is None:
-            session_handler = SessionHandler()
-        self._session_handler = session_handler
-        self._region_name = region_name
+    def __init__(self, botocore_session):
+        self._session_handler = SessionHandler(botocore_session)
 
-    def get_token(self, cluster_name, role_arn):
+    def get_token(self, cluster_name, role_arn, region_name=None):
         """ Generate a presigned url token to pass to kubectl. """
-        url = self._get_presigned_url(cluster_name, role_arn)
+        url = self._get_presigned_url(cluster_name, role_arn, region_name)
         token = TOKEN_PREFIX + base64.urlsafe_b64encode(url.encode('utf-8')).decode('utf-8').rstrip('=')
         return token
 
-    def _get_presigned_url(self, cluster_name, role_arn):
+    def _get_presigned_url(self, cluster_name, role_arn, region_name=None):
         session = self._session_handler.get_session(
-            self._region_name,
+            region_name,
             role_arn
         )
 
-        if self._region_name is None:
-            self._region_name = session.get_config_variable('region')
+        if region_name is None:
+            region_name = session.get_config_variable('region')
 
         loader = botocore.loaders.create_loader()
         data = loader.load_data("endpoints")
         endpoint_resolver = botocore.regions.EndpointResolver(data)
         endpoint = endpoint_resolver.construct_endpoint(
             AUTH_SERVICE,
-            self._region_name
+            region_name
         )
         signer = RequestSigner(
             ServiceId(AUTH_SERVICE),
-            self._region_name,
+            region_name,
             AUTH_SERVICE,
             AUTH_SIGNING_VERSION,
             session.get_credentials(),
@@ -128,11 +127,14 @@
         return url
 
 class SessionHandler(object):
+    def __init__(self, botocore_session):
+        self._session = botocore_session
+
     def get_session(self, region_name, role_arn):
         """
         Assumes the given role and returns a session object assuming said role.
         """
-        session = botocore.session.get_session()
+        session = self._session
         if region_name is not None:
             session.set_config_variable('region', region_name)

{"golden_diff": "diff --git a/awscli/customizations/eks/get_token.py b/awscli/customizations/eks/get_token.py\n--- a/awscli/customizations/eks/get_token.py\n+++ b/awscli/customizations/eks/get_token.py\n@@ -54,11 +54,13 @@\n         }\n     ]\n \n-    def _run_main(self, parsed_args, parsed_globals):\n-        token_generator = TokenGenerator(parsed_globals.region)\n+    def _run_main(self, parsed_args, parsed_globals, token_generator=None):\n+        if token_generator is None:\n+            token_generator = TokenGenerator(self._session)\n         token = token_generator.get_token(\n             parsed_args.cluster_name,\n-            parsed_args.role_arn\n+            parsed_args.role_arn,\n+            parsed_globals.region,\n         )\n \n         full_object = {\n@@ -74,37 +76,34 @@\n         uni_print('\\n')\n \n class TokenGenerator(object):\n-    def __init__(self, region_name, session_handler=None):\n-        if session_handler is None:\n-            session_handler = SessionHandler()\n-        self._session_handler = session_handler\n-        self._region_name = region_name\n+    def __init__(self, botocore_session):\n+        self._session_handler = SessionHandler(botocore_session)\n \n-    def get_token(self, cluster_name, role_arn):\n+    def get_token(self, cluster_name, role_arn, region_name=None):\n         \"\"\" Generate a presigned url token to pass to kubectl. \"\"\"\n-        url = self._get_presigned_url(cluster_name, role_arn)\n+        url = self._get_presigned_url(cluster_name, role_arn, region_name)\n         token = TOKEN_PREFIX + base64.urlsafe_b64encode(url.encode('utf-8')).decode('utf-8').rstrip('=')\n         return token\n \n-    def _get_presigned_url(self, cluster_name, role_arn):\n+    def _get_presigned_url(self, cluster_name, role_arn, region_name=None):\n         session = self._session_handler.get_session(\n-            self._region_name,\n+            region_name,\n             role_arn\n         )\n \n-        if self._region_name is None:\n-            self._region_name = session.get_config_variable('region')\n+        if region_name is None:\n+            region_name = session.get_config_variable('region')\n \n         loader = botocore.loaders.create_loader()\n         data = loader.load_data(\"endpoints\")\n         endpoint_resolver = botocore.regions.EndpointResolver(data)\n         endpoint = endpoint_resolver.construct_endpoint(\n             AUTH_SERVICE,\n-            self._region_name\n+            region_name\n         )\n         signer = RequestSigner(\n             ServiceId(AUTH_SERVICE),\n-            self._region_name,\n+            region_name,\n             AUTH_SERVICE,\n             AUTH_SIGNING_VERSION,\n             session.get_credentials(),\n@@ -128,11 +127,14 @@\n         return url\n \n class SessionHandler(object):\n+    def __init__(self, botocore_session):\n+        self._session = botocore_session\n+\n     def get_session(self, region_name, role_arn):\n         \"\"\"\n         Assumes the given role and returns a session object assuming said role.\n         \"\"\"\n-        session = botocore.session.get_session()\n+        session = self._session\n         if region_name is not None:\n             session.set_config_variable('region', region_name)\n", "issue": "aws eks get-token doesn't work with --profile\nWhen going to use `aws --profile profilename eks get-token --cluster-name eksClusterName` I receive the following error `Unable to locate credentials. You can configure credentials by running \"aws configure\".`. However, when I set the ENVVAR of AWS_DEFAULT_PROFILE to the profile I want, the command works fine.\r\n\r\nI verified other eks commands work fine with the --profile option. For example: `aws --profile profilename eks describe-cluster --name eksClusterName` works as expected.\r\n\r\n\r\naws --version                                             \r\naws-cli/1.16.160 Python/3.7.0 Darwin/18.2.0 botocore/1.12.150\n", "before_files": [{"content": "# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\"). You\n# may not use this file except in compliance with the License. A copy of\n# the License is located at\n#\n# http://aws.amazon.com/apache2.0/\n#\n# or in the \"license\" file accompanying this file. This file is\n# distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n# ANY KIND, either express or implied. See the License for the specific\n# language governing permissions and limitations under the License.\nimport base64\nimport botocore\nimport json\n\nfrom botocore import session\nfrom botocore.signers import RequestSigner\nfrom botocore.model import ServiceId\n\nfrom awscli.customizations.commands import BasicCommand\nfrom awscli.customizations.utils import uni_print\n\nAUTH_SERVICE = \"sts\"\nAUTH_COMMAND = \"GetCallerIdentity\"\nAUTH_API_VERSION = \"2011-06-15\"\nAUTH_SIGNING_VERSION = \"v4\"\n\n# Presigned url timeout in seconds\nURL_TIMEOUT = 60\n\nTOKEN_PREFIX = 'k8s-aws-v1.'\n\nCLUSTER_NAME_HEADER = 'x-k8s-aws-id'\n\n\nclass GetTokenCommand(BasicCommand):\n    NAME = 'get-token'\n\n    DESCRIPTION = (\"Get a token for authentication with an Amazon EKS cluster. \"\n                   \"This can be used as an alternative to the \"\n                   \"aws-iam-authenticator.\")\n\n    ARG_TABLE = [\n        {\n            'name': 'cluster-name',\n            'help_text': (\"Specify the name of the Amazon EKS cluster to create a token for.\"),\n            'required': True\n        },\n        {\n            'name': 'role-arn',\n            'help_text': (\"Assume this role for credentials when signing the token.\"),\n            'required': False\n        }\n    ]\n\n    def _run_main(self, parsed_args, parsed_globals):\n        token_generator = TokenGenerator(parsed_globals.region)\n        token = token_generator.get_token(\n            parsed_args.cluster_name,\n            parsed_args.role_arn\n        )\n\n        full_object = {\n            \"kind\": \"ExecCredential\",\n            \"apiVersion\": \"client.authentication.k8s.io/v1alpha1\",\n            \"spec\": {},\n            \"status\": {\n                \"token\": token\n            }\n        }\n\n        uni_print(json.dumps(full_object))\n        uni_print('\\n')\n\nclass TokenGenerator(object):\n    def __init__(self, region_name, session_handler=None):\n        if session_handler is None:\n            session_handler = SessionHandler()\n        self._session_handler = session_handler\n        self._region_name = region_name\n\n    def get_token(self, cluster_name, role_arn):\n        \"\"\" Generate a presigned url token to pass to kubectl. \"\"\"\n        url = self._get_presigned_url(cluster_name, role_arn)\n        token = TOKEN_PREFIX + base64.urlsafe_b64encode(url.encode('utf-8')).decode('utf-8').rstrip('=')\n        return token\n\n    def _get_presigned_url(self, cluster_name, role_arn):\n        session = self._session_handler.get_session(\n            self._region_name,\n            role_arn\n        )\n\n        if self._region_name is None:\n            self._region_name = session.get_config_variable('region')\n\n        loader = botocore.loaders.create_loader()\n        data = loader.load_data(\"endpoints\")\n        endpoint_resolver = botocore.regions.EndpointResolver(data)\n        endpoint = endpoint_resolver.construct_endpoint(\n            AUTH_SERVICE,\n            self._region_name\n        )\n        signer = RequestSigner(\n            ServiceId(AUTH_SERVICE),\n            self._region_name,\n            AUTH_SERVICE,\n            AUTH_SIGNING_VERSION,\n            session.get_credentials(),\n            session.get_component('event_emitter')\n        )\n        action_params='Action=' + AUTH_COMMAND + '&Version=' + AUTH_API_VERSION\n        params = {\n            'method': 'GET',\n            'url': 'https://' + endpoint[\"hostname\"] + '/?' + action_params,\n            'body': {},\n            'headers': {CLUSTER_NAME_HEADER: cluster_name},\n            'context': {}\n        }\n\n        url=signer.generate_presigned_url(\n            params,\n            region_name=endpoint[\"credentialScope\"][\"region\"],\n            operation_name='',\n            expires_in=URL_TIMEOUT\n        )\n        return url\n\nclass SessionHandler(object):\n    def get_session(self, region_name, role_arn):\n        \"\"\"\n        Assumes the given role and returns a session object assuming said role.\n        \"\"\"\n        session = botocore.session.get_session()\n        if region_name is not None:\n            session.set_config_variable('region', region_name)\n\n        if role_arn is not None:\n            sts = session.create_client(AUTH_SERVICE, region_name=region_name)\n            credentials_dict = sts.assume_role(\n                RoleArn=role_arn,\n                RoleSessionName='EKSGetTokenAuth'\n            )['Credentials']\n\n            session.set_credentials(credentials_dict['AccessKeyId'],\n                                    credentials_dict['SecretAccessKey'],\n                                    credentials_dict['SessionToken'])\n            return session\n        else:\n            return session\n", "path": "awscli/customizations/eks/get_token.py"}], "after_files": [{"content": "# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\"). You\n# may not use this file except in compliance with the License. A copy of\n# the License is located at\n#\n# http://aws.amazon.com/apache2.0/\n#\n# or in the \"license\" file accompanying this file. This file is\n# distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n# ANY KIND, either express or implied. See the License for the specific\n# language governing permissions and limitations under the License.\nimport base64\nimport botocore\nimport json\n\nfrom botocore import session\nfrom botocore.signers import RequestSigner\nfrom botocore.model import ServiceId\n\nfrom awscli.customizations.commands import BasicCommand\nfrom awscli.customizations.utils import uni_print\n\nAUTH_SERVICE = \"sts\"\nAUTH_COMMAND = \"GetCallerIdentity\"\nAUTH_API_VERSION = \"2011-06-15\"\nAUTH_SIGNING_VERSION = \"v4\"\n\n# Presigned url timeout in seconds\nURL_TIMEOUT = 60\n\nTOKEN_PREFIX = 'k8s-aws-v1.'\n\nCLUSTER_NAME_HEADER = 'x-k8s-aws-id'\n\n\nclass GetTokenCommand(BasicCommand):\n    NAME = 'get-token'\n\n    DESCRIPTION = (\"Get a token for authentication with an Amazon EKS cluster. \"\n                   \"This can be used as an alternative to the \"\n                   \"aws-iam-authenticator.\")\n\n    ARG_TABLE = [\n        {\n            'name': 'cluster-name',\n            'help_text': (\"Specify the name of the Amazon EKS cluster to create a token for.\"),\n            'required': True\n        },\n        {\n            'name': 'role-arn',\n            'help_text': (\"Assume this role for credentials when signing the token.\"),\n            'required': False\n        }\n    ]\n\n    def _run_main(self, parsed_args, parsed_globals, token_generator=None):\n        if token_generator is None:\n            token_generator = TokenGenerator(self._session)\n        token = token_generator.get_token(\n            parsed_args.cluster_name,\n            parsed_args.role_arn,\n            parsed_globals.region,\n        )\n\n        full_object = {\n            \"kind\": \"ExecCredential\",\n            \"apiVersion\": \"client.authentication.k8s.io/v1alpha1\",\n            \"spec\": {},\n            \"status\": {\n                \"token\": token\n            }\n        }\n\n        uni_print(json.dumps(full_object))\n        uni_print('\\n')\n\nclass TokenGenerator(object):\n    def __init__(self, botocore_session):\n        self._session_handler = SessionHandler(botocore_session)\n\n    def get_token(self, cluster_name, role_arn, region_name=None):\n        \"\"\" Generate a presigned url token to pass to kubectl. \"\"\"\n        url = self._get_presigned_url(cluster_name, role_arn, region_name)\n        token = TOKEN_PREFIX + base64.urlsafe_b64encode(url.encode('utf-8')).decode('utf-8').rstrip('=')\n        return token\n\n    def _get_presigned_url(self, cluster_name, role_arn, region_name=None):\n        session = self._session_handler.get_session(\n            region_name,\n            role_arn\n        )\n\n        if region_name is None:\n            region_name = session.get_config_variable('region')\n\n        loader = botocore.loaders.create_loader()\n        data = loader.load_data(\"endpoints\")\n        endpoint_resolver = botocore.regions.EndpointResolver(data)\n        endpoint = endpoint_resolver.construct_endpoint(\n            AUTH_SERVICE,\n            region_name\n        )\n        signer = RequestSigner(\n            ServiceId(AUTH_SERVICE),\n            region_name,\n            AUTH_SERVICE,\n            AUTH_SIGNING_VERSION,\n            session.get_credentials(),\n            session.get_component('event_emitter')\n        )\n        action_params='Action=' + AUTH_COMMAND + '&Version=' + AUTH_API_VERSION\n        params = {\n            'method': 'GET',\n            'url': 'https://' + endpoint[\"hostname\"] + '/?' + action_params,\n            'body': {},\n            'headers': {CLUSTER_NAME_HEADER: cluster_name},\n            'context': {}\n        }\n\n        url=signer.generate_presigned_url(\n            params,\n            region_name=endpoint[\"credentialScope\"][\"region\"],\n            operation_name='',\n            expires_in=URL_TIMEOUT\n        )\n        return url\n\nclass SessionHandler(object):\n    def __init__(self, botocore_session):\n        self._session = botocore_session\n\n    def get_session(self, region_name, role_arn):\n        \"\"\"\n        Assumes the given role and returns a session object assuming said role.\n        \"\"\"\n        session = self._session\n        if region_name is not None:\n            session.set_config_variable('region', region_name)\n\n        if role_arn is not None:\n            sts = session.create_client(AUTH_SERVICE, region_name=region_name)\n            credentials_dict = sts.assume_role(\n                RoleArn=role_arn,\n                RoleSessionName='EKSGetTokenAuth'\n            )['Credentials']\n\n            session.set_credentials(credentials_dict['AccessKeyId'],\n                                    credentials_dict['SecretAccessKey'],\n                                    credentials_dict['SessionToken'])\n            return session\n        else:\n            return session\n", "path": "awscli/customizations/eks/get_token.py"}]}