We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Expires timestamp in bundle-instance policy is incorrect
If you do not supply a policy to `aws ec2 bundle-instance` the command will generate a policy for you which includes an expiration of the policy in 24 hours.  The ISO timestamp included in the policy, however, needs to include the `Z` suffix to denote UTC time.


--- 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/ec2bundleinstance.py`
Content:
```
1 # Copyright 2013 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 
14 import logging
15 from hashlib import sha1
16 import hmac
17 import base64
18 import datetime
19 
20 import six
21 
22 from awscli.arguments import CustomArgument
23 
24 logger = logging.getLogger('ec2bundleinstance')
25 
26 # This customization adds the following scalar parameters to the
27 # bundle-instance operation:
28 
29 # --bucket:
30 BUCKET_DOCS = ('The bucket in which to store the AMI.  '
31                'You can specify a bucket that you already own or '
32                'a new bucket that Amazon EC2 creates on your behalf.  '
33                'If you specify a bucket that belongs to someone else, '
34                'Amazon EC2 returns an error.')
35 
36 # --prefix:
37 PREFIX_DOCS = ('The prefix for the image component names being stored '
38                'in Amazon S3.')
39 
40 # --owner-akid
41 OWNER_AKID_DOCS = 'The access key ID of the owner of the Amazon S3 bucket.'
42 
43 # --policy
44 POLICY_DOCS = ("An Amazon S3 upload policy that gives "
45                "Amazon EC2 permission to upload items into Amazon S3 "
46                "on the user's behalf. If you provide this parameter, "
47                "you must also provide "
48                "your secret access key, so we can create a policy "
49                "signature for you (the secret access key is not passed "
50                "to Amazon EC2). If you do not provide this parameter, "
51                "we generate an upload policy for you automatically. "
52                "For more information about upload policies see the "
53                "sections about policy construction and signatures in the "
54                '<a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/HTTPPOSTForms.html">'
55                'Amazon Simple Storage Service Developer Guide</a>.')
56 
57 # --owner-sak
58 OWNER_SAK_DOCS = ('The AWS secret access key for the owner of the '
59                   'Amazon S3 bucket specified in the --bucket '
60                   'parameter. This parameter is required so that a '
61                   'signature can be computed for the policy.')
62 
63 
64 def _add_params(argument_table, operation, **kwargs):
65     # Add the scalar parameters and also change the complex storage
66     # param to not be required so the user doesn't get an error from
67     # argparse if they only supply scalar params.
68     storage_arg = argument_table.get('storage')
69     storage_param = storage_arg.argument_object
70     storage_param.required = False
71     arg = BundleArgument(storage_param='Bucket',
72                          name='bucket',
73                          help_text=BUCKET_DOCS)
74     argument_table['bucket'] = arg
75     arg = BundleArgument(storage_param='Prefix',
76                          name='prefix',
77                          help_text=PREFIX_DOCS)
78     argument_table['prefix'] = arg
79     arg = BundleArgument(storage_param='AWSAccessKeyId',
80                          name='owner-akid',
81                          help_text=OWNER_AKID_DOCS)
82     argument_table['owner-akid'] = arg
83     arg = BundleArgument(storage_param='_SAK',
84                          name='owner-sak',
85                          help_text=OWNER_SAK_DOCS)
86     argument_table['owner-sak'] = arg
87     arg = BundleArgument(storage_param='UploadPolicy',
88                          name='policy',
89                          help_text=POLICY_DOCS)
90     argument_table['policy'] = arg
91 
92 
93 def _check_args(parsed_args, **kwargs):
94     # This function checks the parsed args.  If the user specified
95     # the --ip-permissions option with any of the scalar options we
96     # raise an error.
97     logger.debug(parsed_args)
98     arg_dict = vars(parsed_args)
99     if arg_dict['storage']:
100         for key in ('bucket', 'prefix', 'owner-akid',
101                     'owner-sak', 'policy'):
102             if arg_dict[key]:
103                 msg = ('Mixing the --storage option '
104                        'with the simple, scalar options is '
105                        'not recommended.')
106                 raise ValueError(msg)
107 
108 POLICY = ('{{"expiration": "{expires}",'
109           '"conditions": ['
110           '{{"bucket": "{bucket}"}},'
111           '{{"acl": "ec2-bundle-read"}},'
112           '["starts-with", "$key", "{prefix}"]'
113           ']}}'
114           )
115 
116 
117 def _generate_policy(params):
118     # Called if there is no policy supplied by the user.
119     # Creates a policy that provides access for 24 hours.
120     delta = datetime.timedelta(hours=24)
121     expires = datetime.datetime.utcnow() + delta
122     policy = POLICY.format(expires=expires.isoformat(),
123                            bucket=params['Bucket'],
124                            prefix=params['Prefix'])
125     params['UploadPolicy'] = policy
126 
127 
128 def _generate_signature(params):
129     # If we have a policy and a sak, create the signature.
130     policy = params.get('UploadPolicy')
131     sak = params.get('_SAK')
132     if policy and sak:
133         policy = base64.b64encode(six.b(policy)).decode('utf-8')
134         new_hmac = hmac.new(sak.encode('utf-8'), digestmod=sha1)
135         new_hmac.update(six.b(policy))
136         ps = base64.encodestring(new_hmac.digest()).strip().decode('utf-8')
137         params['UploadPolicySignature'] = ps
138         del params['_SAK']
139 
140 
141 def _check_params(**kwargs):
142     # Called just before call but prior to building the params.
143     # Adds information not supplied by the user.
144     logger.debug(kwargs)
145     storage = kwargs['params']['storage']['S3']
146     if 'UploadPolicy' not in storage:
147         _generate_policy(storage)
148     if 'UploadPolicySignature' not in storage:
149         _generate_signature(storage)
150 
151 
152 EVENTS = [
153     ('building-argument-table.ec2.bundle-instance', _add_params),
154     ('operation-args-parsed.ec2.bundle-instance', _check_args),
155     ('before-parameter-build.ec2.BundleInstance', _check_params),
156     ]
157 
158 
159 def register_bundleinstance(event_handler):
160     # Register all of the events for customizing BundleInstance
161     for event, handler in EVENTS:
162         event_handler.register(event, handler)
163 
164 
165 class BundleArgument(CustomArgument):
166 
167     def __init__(self, storage_param, *args, **kwargs):
168         super(BundleArgument, self).__init__(*args, **kwargs)
169         self._storage_param = storage_param
170 
171     def _build_storage(self, params, value):
172         # Build up the Storage data structure
173         if 'storage' not in params:
174             params['storage'] = {'S3': {}}
175         params['storage']['S3'][self._storage_param] = value
176 
177 
178     def add_to_params(self, parameters, value):
179         if value:
180             self._build_storage(parameters, value)
181
```
--- 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/ec2bundleinstance.py b/awscli/customizations/ec2bundleinstance.py
--- a/awscli/customizations/ec2bundleinstance.py
+++ b/awscli/customizations/ec2bundleinstance.py
@@ -119,7 +119,8 @@
     # Creates a policy that provides access for 24 hours.
     delta = datetime.timedelta(hours=24)
     expires = datetime.datetime.utcnow() + delta
-    policy = POLICY.format(expires=expires.isoformat(),
+    expires_iso = expires.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
+    policy = POLICY.format(expires=expires_iso,
                            bucket=params['Bucket'],
                            prefix=params['Prefix'])
     params['UploadPolicy'] = policy

{"golden_diff": "diff --git a/awscli/customizations/ec2bundleinstance.py b/awscli/customizations/ec2bundleinstance.py\n--- a/awscli/customizations/ec2bundleinstance.py\n+++ b/awscli/customizations/ec2bundleinstance.py\n@@ -119,7 +119,8 @@\n     # Creates a policy that provides access for 24 hours.\n     delta = datetime.timedelta(hours=24)\n     expires = datetime.datetime.utcnow() + delta\n-    policy = POLICY.format(expires=expires.isoformat(),\n+    expires_iso = expires.strftime(\"%Y-%m-%dT%H:%M:%S.%fZ\")\n+    policy = POLICY.format(expires=expires_iso,\n                            bucket=params['Bucket'],\n                            prefix=params['Prefix'])\n     params['UploadPolicy'] = policy\n", "issue": "Expires timestamp in bundle-instance policy is incorrect\nIf you do not supply a policy to `aws ec2 bundle-instance` the command will generate a policy for you which includes an expiration of the policy in 24 hours.  The ISO timestamp included in the policy, however, needs to include the `Z` suffix to denote UTC time.\n\n", "before_files": [{"content": "# Copyright 2013 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.\n\nimport logging\nfrom hashlib import sha1\nimport hmac\nimport base64\nimport datetime\n\nimport six\n\nfrom awscli.arguments import CustomArgument\n\nlogger = logging.getLogger('ec2bundleinstance')\n\n# This customization adds the following scalar parameters to the\n# bundle-instance operation:\n\n# --bucket:\nBUCKET_DOCS = ('The bucket in which to store the AMI.  '\n               'You can specify a bucket that you already own or '\n               'a new bucket that Amazon EC2 creates on your behalf.  '\n               'If you specify a bucket that belongs to someone else, '\n               'Amazon EC2 returns an error.')\n\n# --prefix:\nPREFIX_DOCS = ('The prefix for the image component names being stored '\n               'in Amazon S3.')\n\n# --owner-akid\nOWNER_AKID_DOCS = 'The access key ID of the owner of the Amazon S3 bucket.'\n\n# --policy\nPOLICY_DOCS = (\"An Amazon S3 upload policy that gives \"\n               \"Amazon EC2 permission to upload items into Amazon S3 \"\n               \"on the user's behalf. If you provide this parameter, \"\n               \"you must also provide \"\n               \"your secret access key, so we can create a policy \"\n               \"signature for you (the secret access key is not passed \"\n               \"to Amazon EC2). If you do not provide this parameter, \"\n               \"we generate an upload policy for you automatically. \"\n               \"For more information about upload policies see the \"\n               \"sections about policy construction and signatures in the \"\n               '<a href=\"http://docs.aws.amazon.com/AmazonS3/latest/dev/HTTPPOSTForms.html\">'\n               'Amazon Simple Storage Service Developer Guide</a>.')\n\n# --owner-sak\nOWNER_SAK_DOCS = ('The AWS secret access key for the owner of the '\n                  'Amazon S3 bucket specified in the --bucket '\n                  'parameter. This parameter is required so that a '\n                  'signature can be computed for the policy.')\n\n\ndef _add_params(argument_table, operation, **kwargs):\n    # Add the scalar parameters and also change the complex storage\n    # param to not be required so the user doesn't get an error from\n    # argparse if they only supply scalar params.\n    storage_arg = argument_table.get('storage')\n    storage_param = storage_arg.argument_object\n    storage_param.required = False\n    arg = BundleArgument(storage_param='Bucket',\n                         name='bucket',\n                         help_text=BUCKET_DOCS)\n    argument_table['bucket'] = arg\n    arg = BundleArgument(storage_param='Prefix',\n                         name='prefix',\n                         help_text=PREFIX_DOCS)\n    argument_table['prefix'] = arg\n    arg = BundleArgument(storage_param='AWSAccessKeyId',\n                         name='owner-akid',\n                         help_text=OWNER_AKID_DOCS)\n    argument_table['owner-akid'] = arg\n    arg = BundleArgument(storage_param='_SAK',\n                         name='owner-sak',\n                         help_text=OWNER_SAK_DOCS)\n    argument_table['owner-sak'] = arg\n    arg = BundleArgument(storage_param='UploadPolicy',\n                         name='policy',\n                         help_text=POLICY_DOCS)\n    argument_table['policy'] = arg\n\n\ndef _check_args(parsed_args, **kwargs):\n    # This function checks the parsed args.  If the user specified\n    # the --ip-permissions option with any of the scalar options we\n    # raise an error.\n    logger.debug(parsed_args)\n    arg_dict = vars(parsed_args)\n    if arg_dict['storage']:\n        for key in ('bucket', 'prefix', 'owner-akid',\n                    'owner-sak', 'policy'):\n            if arg_dict[key]:\n                msg = ('Mixing the --storage option '\n                       'with the simple, scalar options is '\n                       'not recommended.')\n                raise ValueError(msg)\n\nPOLICY = ('{{\"expiration\": \"{expires}\",'\n          '\"conditions\": ['\n          '{{\"bucket\": \"{bucket}\"}},'\n          '{{\"acl\": \"ec2-bundle-read\"}},'\n          '[\"starts-with\", \"$key\", \"{prefix}\"]'\n          ']}}'\n          )\n\n\ndef _generate_policy(params):\n    # Called if there is no policy supplied by the user.\n    # Creates a policy that provides access for 24 hours.\n    delta = datetime.timedelta(hours=24)\n    expires = datetime.datetime.utcnow() + delta\n    policy = POLICY.format(expires=expires.isoformat(),\n                           bucket=params['Bucket'],\n                           prefix=params['Prefix'])\n    params['UploadPolicy'] = policy\n\n\ndef _generate_signature(params):\n    # If we have a policy and a sak, create the signature.\n    policy = params.get('UploadPolicy')\n    sak = params.get('_SAK')\n    if policy and sak:\n        policy = base64.b64encode(six.b(policy)).decode('utf-8')\n        new_hmac = hmac.new(sak.encode('utf-8'), digestmod=sha1)\n        new_hmac.update(six.b(policy))\n        ps = base64.encodestring(new_hmac.digest()).strip().decode('utf-8')\n        params['UploadPolicySignature'] = ps\n        del params['_SAK']\n\n\ndef _check_params(**kwargs):\n    # Called just before call but prior to building the params.\n    # Adds information not supplied by the user.\n    logger.debug(kwargs)\n    storage = kwargs['params']['storage']['S3']\n    if 'UploadPolicy' not in storage:\n        _generate_policy(storage)\n    if 'UploadPolicySignature' not in storage:\n        _generate_signature(storage)\n\n\nEVENTS = [\n    ('building-argument-table.ec2.bundle-instance', _add_params),\n    ('operation-args-parsed.ec2.bundle-instance', _check_args),\n    ('before-parameter-build.ec2.BundleInstance', _check_params),\n    ]\n\n\ndef register_bundleinstance(event_handler):\n    # Register all of the events for customizing BundleInstance\n    for event, handler in EVENTS:\n        event_handler.register(event, handler)\n\n\nclass BundleArgument(CustomArgument):\n\n    def __init__(self, storage_param, *args, **kwargs):\n        super(BundleArgument, self).__init__(*args, **kwargs)\n        self._storage_param = storage_param\n\n    def _build_storage(self, params, value):\n        # Build up the Storage data structure\n        if 'storage' not in params:\n            params['storage'] = {'S3': {}}\n        params['storage']['S3'][self._storage_param] = value\n\n\n    def add_to_params(self, parameters, value):\n        if value:\n            self._build_storage(parameters, value)\n", "path": "awscli/customizations/ec2bundleinstance.py"}], "after_files": [{"content": "# Copyright 2013 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.\n\nimport logging\nfrom hashlib import sha1\nimport hmac\nimport base64\nimport datetime\n\nimport six\n\nfrom awscli.arguments import CustomArgument\n\nlogger = logging.getLogger('ec2bundleinstance')\n\n# This customization adds the following scalar parameters to the\n# bundle-instance operation:\n\n# --bucket:\nBUCKET_DOCS = ('The bucket in which to store the AMI.  '\n               'You can specify a bucket that you already own or '\n               'a new bucket that Amazon EC2 creates on your behalf.  '\n               'If you specify a bucket that belongs to someone else, '\n               'Amazon EC2 returns an error.')\n\n# --prefix:\nPREFIX_DOCS = ('The prefix for the image component names being stored '\n               'in Amazon S3.')\n\n# --owner-akid\nOWNER_AKID_DOCS = 'The access key ID of the owner of the Amazon S3 bucket.'\n\n# --policy\nPOLICY_DOCS = (\"An Amazon S3 upload policy that gives \"\n               \"Amazon EC2 permission to upload items into Amazon S3 \"\n               \"on the user's behalf. If you provide this parameter, \"\n               \"you must also provide \"\n               \"your secret access key, so we can create a policy \"\n               \"signature for you (the secret access key is not passed \"\n               \"to Amazon EC2). If you do not provide this parameter, \"\n               \"we generate an upload policy for you automatically. \"\n               \"For more information about upload policies see the \"\n               \"sections about policy construction and signatures in the \"\n               '<a href=\"http://docs.aws.amazon.com/AmazonS3/latest/dev/HTTPPOSTForms.html\">'\n               'Amazon Simple Storage Service Developer Guide</a>.')\n\n# --owner-sak\nOWNER_SAK_DOCS = ('The AWS secret access key for the owner of the '\n                  'Amazon S3 bucket specified in the --bucket '\n                  'parameter. This parameter is required so that a '\n                  'signature can be computed for the policy.')\n\n\ndef _add_params(argument_table, operation, **kwargs):\n    # Add the scalar parameters and also change the complex storage\n    # param to not be required so the user doesn't get an error from\n    # argparse if they only supply scalar params.\n    storage_arg = argument_table.get('storage')\n    storage_param = storage_arg.argument_object\n    storage_param.required = False\n    arg = BundleArgument(storage_param='Bucket',\n                         name='bucket',\n                         help_text=BUCKET_DOCS)\n    argument_table['bucket'] = arg\n    arg = BundleArgument(storage_param='Prefix',\n                         name='prefix',\n                         help_text=PREFIX_DOCS)\n    argument_table['prefix'] = arg\n    arg = BundleArgument(storage_param='AWSAccessKeyId',\n                         name='owner-akid',\n                         help_text=OWNER_AKID_DOCS)\n    argument_table['owner-akid'] = arg\n    arg = BundleArgument(storage_param='_SAK',\n                         name='owner-sak',\n                         help_text=OWNER_SAK_DOCS)\n    argument_table['owner-sak'] = arg\n    arg = BundleArgument(storage_param='UploadPolicy',\n                         name='policy',\n                         help_text=POLICY_DOCS)\n    argument_table['policy'] = arg\n\n\ndef _check_args(parsed_args, **kwargs):\n    # This function checks the parsed args.  If the user specified\n    # the --ip-permissions option with any of the scalar options we\n    # raise an error.\n    logger.debug(parsed_args)\n    arg_dict = vars(parsed_args)\n    if arg_dict['storage']:\n        for key in ('bucket', 'prefix', 'owner-akid',\n                    'owner-sak', 'policy'):\n            if arg_dict[key]:\n                msg = ('Mixing the --storage option '\n                       'with the simple, scalar options is '\n                       'not recommended.')\n                raise ValueError(msg)\n\nPOLICY = ('{{\"expiration\": \"{expires}\",'\n          '\"conditions\": ['\n          '{{\"bucket\": \"{bucket}\"}},'\n          '{{\"acl\": \"ec2-bundle-read\"}},'\n          '[\"starts-with\", \"$key\", \"{prefix}\"]'\n          ']}}'\n          )\n\n\ndef _generate_policy(params):\n    # Called if there is no policy supplied by the user.\n    # Creates a policy that provides access for 24 hours.\n    delta = datetime.timedelta(hours=24)\n    expires = datetime.datetime.utcnow() + delta\n    expires_iso = expires.strftime(\"%Y-%m-%dT%H:%M:%S.%fZ\")\n    policy = POLICY.format(expires=expires_iso,\n                           bucket=params['Bucket'],\n                           prefix=params['Prefix'])\n    params['UploadPolicy'] = policy\n\n\ndef _generate_signature(params):\n    # If we have a policy and a sak, create the signature.\n    policy = params.get('UploadPolicy')\n    sak = params.get('_SAK')\n    if policy and sak:\n        policy = base64.b64encode(six.b(policy)).decode('utf-8')\n        new_hmac = hmac.new(sak.encode('utf-8'), digestmod=sha1)\n        new_hmac.update(six.b(policy))\n        ps = base64.encodestring(new_hmac.digest()).strip().decode('utf-8')\n        params['UploadPolicySignature'] = ps\n        del params['_SAK']\n\n\ndef _check_params(**kwargs):\n    # Called just before call but prior to building the params.\n    # Adds information not supplied by the user.\n    logger.debug(kwargs)\n    storage = kwargs['params']['storage']['S3']\n    if 'UploadPolicy' not in storage:\n        _generate_policy(storage)\n    if 'UploadPolicySignature' not in storage:\n        _generate_signature(storage)\n\n\nEVENTS = [\n    ('building-argument-table.ec2.bundle-instance', _add_params),\n    ('operation-args-parsed.ec2.bundle-instance', _check_args),\n    ('before-parameter-build.ec2.BundleInstance', _check_params),\n    ]\n\n\ndef register_bundleinstance(event_handler):\n    # Register all of the events for customizing BundleInstance\n    for event, handler in EVENTS:\n        event_handler.register(event, handler)\n\n\nclass BundleArgument(CustomArgument):\n\n    def __init__(self, storage_param, *args, **kwargs):\n        super(BundleArgument, self).__init__(*args, **kwargs)\n        self._storage_param = storage_param\n\n    def _build_storage(self, params, value):\n        # Build up the Storage data structure\n        if 'storage' not in params:\n            params['storage'] = {'S3': {}}\n        params['storage']['S3'][self._storage_param] = value\n\n\n    def add_to_params(self, parameters, value):\n        if value:\n            self._build_storage(parameters, value)\n", "path": "awscli/customizations/ec2bundleinstance.py"}]}