prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  AWS CLI configuration does not respect profile variable
  I tried to use the command aws ec2 describe-spot-price-history in the CLI and received the error 'You must specify a region. You can also configure your region by running "aws configure".' When I first installed the CLI, I configured my credentials and region.
  
  Running 'aws configure', I try to re-enter my details (they are listed as blank), but they do not save. I assume this is because I am using a profile. I have the environment variable AWS_DEFAULT_PROFILE set to 'internal', and have attached my configuration files (with .txt extension added and sensitive data redacted).
  
  [config.txt](https://github.com/aws/aws-cli/files/1486174/config.txt)
  [credentials.txt](https://github.com/aws/aws-cli/files/1486175/credentials.txt)
  
  --- 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/configure/configure.py`
  Content:
  ```
  1 # Copyright 2016 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 os
  14 import logging
  15 
  16 from botocore.exceptions import ProfileNotFound
  17 
  18 from awscli.compat import compat_input
  19 from awscli.customizations.commands import BasicCommand
  20 from awscli.customizations.configure.addmodel import AddModelCommand
  21 from awscli.customizations.configure.set import ConfigureSetCommand
  22 from awscli.customizations.configure.get import ConfigureGetCommand
  23 from awscli.customizations.configure.list import ConfigureListCommand
  24 from awscli.customizations.configure.writer import ConfigFileWriter
  25 
  26 from . import mask_value, profile_to_section
  27 
  28 
  29 logger = logging.getLogger(__name__)
  30 
  31 
  32 def register_configure_cmd(cli):
  33     cli.register('building-command-table.main',
  34                  ConfigureCommand.add_command)
  35 
  36 
  37 class InteractivePrompter(object):
  38 
  39     def get_value(self, current_value, config_name, prompt_text=''):
  40         if config_name in ('aws_access_key_id', 'aws_secret_access_key'):
  41             current_value = mask_value(current_value)
  42         response = compat_input("%s [%s]: " % (prompt_text, current_value))
  43         if not response:
  44             # If the user hits enter, we return a value of None
  45             # instead of an empty string.  That way we can determine
  46             # whether or not a value has changed.
  47             response = None
  48         return response
  49 
  50 
  51 class ConfigureCommand(BasicCommand):
  52     NAME = 'configure'
  53     DESCRIPTION = BasicCommand.FROM_FILE()
  54     SYNOPSIS = ('aws configure [--profile profile-name]')
  55     EXAMPLES = (
  56         'To create a new configuration::\n'
  57         '\n'
  58         '    $ aws configure\n'
  59         '    AWS Access Key ID [None]: accesskey\n'
  60         '    AWS Secret Access Key [None]: secretkey\n'
  61         '    Default region name [None]: us-west-2\n'
  62         '    Default output format [None]:\n'
  63         '\n'
  64         'To update just the region name::\n'
  65         '\n'
  66         '    $ aws configure\n'
  67         '    AWS Access Key ID [****]:\n'
  68         '    AWS Secret Access Key [****]:\n'
  69         '    Default region name [us-west-1]: us-west-2\n'
  70         '    Default output format [None]:\n'
  71     )
  72     SUBCOMMANDS = [
  73         {'name': 'list', 'command_class': ConfigureListCommand},
  74         {'name': 'get', 'command_class': ConfigureGetCommand},
  75         {'name': 'set', 'command_class': ConfigureSetCommand},
  76         {'name': 'add-model', 'command_class': AddModelCommand}
  77     ]
  78 
  79     # If you want to add new values to prompt, update this list here.
  80     VALUES_TO_PROMPT = [
  81         # (logical_name, config_name, prompt_text)
  82         ('aws_access_key_id', "AWS Access Key ID"),
  83         ('aws_secret_access_key', "AWS Secret Access Key"),
  84         ('region', "Default region name"),
  85         ('output', "Default output format"),
  86     ]
  87 
  88     def __init__(self, session, prompter=None, config_writer=None):
  89         super(ConfigureCommand, self).__init__(session)
  90         if prompter is None:
  91             prompter = InteractivePrompter()
  92         self._prompter = prompter
  93         if config_writer is None:
  94             config_writer = ConfigFileWriter()
  95         self._config_writer = config_writer
  96 
  97     def _run_main(self, parsed_args, parsed_globals):
  98         # Called when invoked with no args "aws configure"
  99         new_values = {}
  100         # This is the config from the config file scoped to a specific
  101         # profile.
  102         try:
  103             config = self._session.get_scoped_config()
  104         except ProfileNotFound:
  105             config = {}
  106         for config_name, prompt_text in self.VALUES_TO_PROMPT:
  107             current_value = config.get(config_name)
  108             new_value = self._prompter.get_value(current_value, config_name,
  109                                                  prompt_text)
  110             if new_value is not None and new_value != current_value:
  111                 new_values[config_name] = new_value
  112         config_filename = os.path.expanduser(
  113             self._session.get_config_variable('config_file'))
  114         if new_values:
  115             self._write_out_creds_file_values(new_values,
  116                                               parsed_globals.profile)
  117             if parsed_globals.profile is not None:
  118                 section = profile_to_section(parsed_globals.profile)
  119                 new_values['__section__'] = section
  120             self._config_writer.update_config(new_values, config_filename)
  121 
  122     def _write_out_creds_file_values(self, new_values, profile_name):
  123         # The access_key/secret_key are now *always* written to the shared
  124         # credentials file (~/.aws/credentials), see aws/aws-cli#847.
  125         # post-conditions: ~/.aws/credentials will have the updated credential
  126         # file values and new_values will have the cred vars removed.
  127         credential_file_values = {}
  128         if 'aws_access_key_id' in new_values:
  129             credential_file_values['aws_access_key_id'] = new_values.pop(
  130                 'aws_access_key_id')
  131         if 'aws_secret_access_key' in new_values:
  132             credential_file_values['aws_secret_access_key'] = new_values.pop(
  133                 'aws_secret_access_key')
  134         if credential_file_values:
  135             if profile_name is not None:
  136                 credential_file_values['__section__'] = profile_name
  137             shared_credentials_filename = os.path.expanduser(
  138                 self._session.get_config_variable('credentials_file'))
  139             self._config_writer.update_config(
  140                 credential_file_values,
  141                 shared_credentials_filename)
  142
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/awscli/customizations/configure/configure.py b/awscli/customizations/configure/configure.py
  --- a/awscli/customizations/configure/configure.py
  +++ b/awscli/customizations/configure/configure.py
  @@ -112,10 +112,10 @@
           config_filename = os.path.expanduser(
               self._session.get_config_variable('config_file'))
           if new_values:
  -            self._write_out_creds_file_values(new_values,
  -                                              parsed_globals.profile)
  -            if parsed_globals.profile is not None:
  -                section = profile_to_section(parsed_globals.profile)
  +            profile = self._session.profile
  +            self._write_out_creds_file_values(new_values, profile)
  +            if profile is not None:
  +                section = profile_to_section(profile)
                   new_values['__section__'] = section
               self._config_writer.update_config(new_values, config_filename)
  
verification_info: {"golden_diff": "diff --git a/awscli/customizations/configure/configure.py b/awscli/customizations/configure/configure.py\n--- a/awscli/customizations/configure/configure.py\n+++ b/awscli/customizations/configure/configure.py\n@@ -112,10 +112,10 @@\n         config_filename = os.path.expanduser(\n             self._session.get_config_variable('config_file'))\n         if new_values:\n-            self._write_out_creds_file_values(new_values,\n-                                              parsed_globals.profile)\n-            if parsed_globals.profile is not None:\n-                section = profile_to_section(parsed_globals.profile)\n+            profile = self._session.profile\n+            self._write_out_creds_file_values(new_values, profile)\n+            if profile is not None:\n+                section = profile_to_section(profile)\n                 new_values['__section__'] = section\n             self._config_writer.update_config(new_values, config_filename)\n", "issue": "AWS CLI configuration does not respect profile variable\nI tried to use the command aws ec2 describe-spot-price-history in the CLI and received the error 'You must specify a region. You can also configure your region by running \"aws configure\".' When I first installed the CLI, I configured my credentials and region.\r\n\r\nRunning 'aws configure', I try to re-enter my details (they are listed as blank), but they do not save. I assume this is because I am using a profile. I have the environment variable AWS_DEFAULT_PROFILE set to 'internal', and have attached my configuration files (with .txt extension added and sensitive data redacted).\r\n\r\n[config.txt](https://github.com/aws/aws-cli/files/1486174/config.txt)\r\n[credentials.txt](https://github.com/aws/aws-cli/files/1486175/credentials.txt)\n", "before_files": [{"content": "# Copyright 2016 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 os\nimport logging\n\nfrom botocore.exceptions import ProfileNotFound\n\nfrom awscli.compat import compat_input\nfrom awscli.customizations.commands import BasicCommand\nfrom awscli.customizations.configure.addmodel import AddModelCommand\nfrom awscli.customizations.configure.set import ConfigureSetCommand\nfrom awscli.customizations.configure.get import ConfigureGetCommand\nfrom awscli.customizations.configure.list import ConfigureListCommand\nfrom awscli.customizations.configure.writer import ConfigFileWriter\n\nfrom . import mask_value, profile_to_section\n\n\nlogger = logging.getLogger(__name__)\n\n\ndef register_configure_cmd(cli):\n    cli.register('building-command-table.main',\n                 ConfigureCommand.add_command)\n\n\nclass InteractivePrompter(object):\n\n    def get_value(self, current_value, config_name, prompt_text=''):\n        if config_name in ('aws_access_key_id', 'aws_secret_access_key'):\n            current_value = mask_value(current_value)\n        response = compat_input(\"%s [%s]: \" % (prompt_text, current_value))\n        if not response:\n            # If the user hits enter, we return a value of None\n            # instead of an empty string.  That way we can determine\n            # whether or not a value has changed.\n            response = None\n        return response\n\n\nclass ConfigureCommand(BasicCommand):\n    NAME = 'configure'\n    DESCRIPTION = BasicCommand.FROM_FILE()\n    SYNOPSIS = ('aws configure [--profile profile-name]')\n    EXAMPLES = (\n        'To create a new configuration::\\n'\n        '\\n'\n        '    $ aws configure\\n'\n        '    AWS Access Key ID [None]: accesskey\\n'\n        '    AWS Secret Access Key [None]: secretkey\\n'\n        '    Default region name [None]: us-west-2\\n'\n        '    Default output format [None]:\\n'\n        '\\n'\n        'To update just the region name::\\n'\n        '\\n'\n        '    $ aws configure\\n'\n        '    AWS Access Key ID [****]:\\n'\n        '    AWS Secret Access Key [****]:\\n'\n        '    Default region name [us-west-1]: us-west-2\\n'\n        '    Default output format [None]:\\n'\n    )\n    SUBCOMMANDS = [\n        {'name': 'list', 'command_class': ConfigureListCommand},\n        {'name': 'get', 'command_class': ConfigureGetCommand},\n        {'name': 'set', 'command_class': ConfigureSetCommand},\n        {'name': 'add-model', 'command_class': AddModelCommand}\n    ]\n\n    # If you want to add new values to prompt, update this list here.\n    VALUES_TO_PROMPT = [\n        # (logical_name, config_name, prompt_text)\n        ('aws_access_key_id', \"AWS Access Key ID\"),\n        ('aws_secret_access_key', \"AWS Secret Access Key\"),\n        ('region', \"Default region name\"),\n        ('output', \"Default output format\"),\n    ]\n\n    def __init__(self, session, prompter=None, config_writer=None):\n        super(ConfigureCommand, self).__init__(session)\n        if prompter is None:\n            prompter = InteractivePrompter()\n        self._prompter = prompter\n        if config_writer is None:\n            config_writer = ConfigFileWriter()\n        self._config_writer = config_writer\n\n    def _run_main(self, parsed_args, parsed_globals):\n        # Called when invoked with no args \"aws configure\"\n        new_values = {}\n        # This is the config from the config file scoped to a specific\n        # profile.\n        try:\n            config = self._session.get_scoped_config()\n        except ProfileNotFound:\n            config = {}\n        for config_name, prompt_text in self.VALUES_TO_PROMPT:\n            current_value = config.get(config_name)\n            new_value = self._prompter.get_value(current_value, config_name,\n                                                 prompt_text)\n            if new_value is not None and new_value != current_value:\n                new_values[config_name] = new_value\n        config_filename = os.path.expanduser(\n            self._session.get_config_variable('config_file'))\n        if new_values:\n            self._write_out_creds_file_values(new_values,\n                                              parsed_globals.profile)\n            if parsed_globals.profile is not None:\n                section = profile_to_section(parsed_globals.profile)\n                new_values['__section__'] = section\n            self._config_writer.update_config(new_values, config_filename)\n\n    def _write_out_creds_file_values(self, new_values, profile_name):\n        # The access_key/secret_key are now *always* written to the shared\n        # credentials file (~/.aws/credentials), see aws/aws-cli#847.\n        # post-conditions: ~/.aws/credentials will have the updated credential\n        # file values and new_values will have the cred vars removed.\n        credential_file_values = {}\n        if 'aws_access_key_id' in new_values:\n            credential_file_values['aws_access_key_id'] = new_values.pop(\n                'aws_access_key_id')\n        if 'aws_secret_access_key' in new_values:\n            credential_file_values['aws_secret_access_key'] = new_values.pop(\n                'aws_secret_access_key')\n        if credential_file_values:\n            if profile_name is not None:\n                credential_file_values['__section__'] = profile_name\n            shared_credentials_filename = os.path.expanduser(\n                self._session.get_config_variable('credentials_file'))\n            self._config_writer.update_config(\n                credential_file_values,\n                shared_credentials_filename)\n", "path": "awscli/customizations/configure/configure.py"}], "after_files": [{"content": "# Copyright 2016 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 os\nimport logging\n\nfrom botocore.exceptions import ProfileNotFound\n\nfrom awscli.compat import compat_input\nfrom awscli.customizations.commands import BasicCommand\nfrom awscli.customizations.configure.addmodel import AddModelCommand\nfrom awscli.customizations.configure.set import ConfigureSetCommand\nfrom awscli.customizations.configure.get import ConfigureGetCommand\nfrom awscli.customizations.configure.list import ConfigureListCommand\nfrom awscli.customizations.configure.writer import ConfigFileWriter\n\nfrom . import mask_value, profile_to_section\n\n\nlogger = logging.getLogger(__name__)\n\n\ndef register_configure_cmd(cli):\n    cli.register('building-command-table.main',\n                 ConfigureCommand.add_command)\n\n\nclass InteractivePrompter(object):\n\n    def get_value(self, current_value, config_name, prompt_text=''):\n        if config_name in ('aws_access_key_id', 'aws_secret_access_key'):\n            current_value = mask_value(current_value)\n        response = compat_input(\"%s [%s]: \" % (prompt_text, current_value))\n        if not response:\n            # If the user hits enter, we return a value of None\n            # instead of an empty string.  That way we can determine\n            # whether or not a value has changed.\n            response = None\n        return response\n\n\nclass ConfigureCommand(BasicCommand):\n    NAME = 'configure'\n    DESCRIPTION = BasicCommand.FROM_FILE()\n    SYNOPSIS = ('aws configure [--profile profile-name]')\n    EXAMPLES = (\n        'To create a new configuration::\\n'\n        '\\n'\n        '    $ aws configure\\n'\n        '    AWS Access Key ID [None]: accesskey\\n'\n        '    AWS Secret Access Key [None]: secretkey\\n'\n        '    Default region name [None]: us-west-2\\n'\n        '    Default output format [None]:\\n'\n        '\\n'\n        'To update just the region name::\\n'\n        '\\n'\n        '    $ aws configure\\n'\n        '    AWS Access Key ID [****]:\\n'\n        '    AWS Secret Access Key [****]:\\n'\n        '    Default region name [us-west-1]: us-west-2\\n'\n        '    Default output format [None]:\\n'\n    )\n    SUBCOMMANDS = [\n        {'name': 'list', 'command_class': ConfigureListCommand},\n        {'name': 'get', 'command_class': ConfigureGetCommand},\n        {'name': 'set', 'command_class': ConfigureSetCommand},\n        {'name': 'add-model', 'command_class': AddModelCommand}\n    ]\n\n    # If you want to add new values to prompt, update this list here.\n    VALUES_TO_PROMPT = [\n        # (logical_name, config_name, prompt_text)\n        ('aws_access_key_id', \"AWS Access Key ID\"),\n        ('aws_secret_access_key', \"AWS Secret Access Key\"),\n        ('region', \"Default region name\"),\n        ('output', \"Default output format\"),\n    ]\n\n    def __init__(self, session, prompter=None, config_writer=None):\n        super(ConfigureCommand, self).__init__(session)\n        if prompter is None:\n            prompter = InteractivePrompter()\n        self._prompter = prompter\n        if config_writer is None:\n            config_writer = ConfigFileWriter()\n        self._config_writer = config_writer\n\n    def _run_main(self, parsed_args, parsed_globals):\n        # Called when invoked with no args \"aws configure\"\n        new_values = {}\n        # This is the config from the config file scoped to a specific\n        # profile.\n        try:\n            config = self._session.get_scoped_config()\n        except ProfileNotFound:\n            config = {}\n        for config_name, prompt_text in self.VALUES_TO_PROMPT:\n            current_value = config.get(config_name)\n            new_value = self._prompter.get_value(current_value, config_name,\n                                                 prompt_text)\n            if new_value is not None and new_value != current_value:\n                new_values[config_name] = new_value\n        config_filename = os.path.expanduser(\n            self._session.get_config_variable('config_file'))\n        if new_values:\n            profile = self._session.profile\n            self._write_out_creds_file_values(new_values, profile)\n            if profile is not None:\n                section = profile_to_section(profile)\n                new_values['__section__'] = section\n            self._config_writer.update_config(new_values, config_filename)\n\n    def _write_out_creds_file_values(self, new_values, profile_name):\n        # The access_key/secret_key are now *always* written to the shared\n        # credentials file (~/.aws/credentials), see aws/aws-cli#847.\n        # post-conditions: ~/.aws/credentials will have the updated credential\n        # file values and new_values will have the cred vars removed.\n        credential_file_values = {}\n        if 'aws_access_key_id' in new_values:\n            credential_file_values['aws_access_key_id'] = new_values.pop(\n                'aws_access_key_id')\n        if 'aws_secret_access_key' in new_values:\n            credential_file_values['aws_secret_access_key'] = new_values.pop(\n                'aws_secret_access_key')\n        if credential_file_values:\n            if profile_name is not None:\n                credential_file_values['__section__'] = profile_name\n            shared_credentials_filename = os.path.expanduser(\n                self._session.get_config_variable('credentials_file'))\n            self._config_writer.update_config(\n                credential_file_values,\n                shared_credentials_filename)\n", "path": "awscli/customizations/configure/configure.py"}]}