AMI identifier string is erroneously padded with brackets
See original GitHub issueThe request_spot_instances
method of an EC2 client erroneously pads the AMI identifier string ImageId
with brackets, resulting in an exception.
import boto3
boto3.set_stream_logger('')
client = boto3.client('ec2')
image_id = 'ami-fake123'
instance_type = 'c5.large'
launch_specification ={'ImageId': image_id, 'InstanceType': instance_type}
client.request_spot_instances(LaunchSpecification=launch_specification)
The method should return a response dict
containing a unique identifier of the spot request. Stack trace is below. Note that I replaced the AMI identifier string with ami-fake123
for security purposes.
2021-07-14 01:42:05,347 botocore.hooks [DEBUG] Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2021-07-14 01:42:05,349 botocore.hooks [DEBUG] Changing event name from before-call.apigateway to before-call.api-gateway
2021-07-14 01:42:05,350 botocore.hooks [DEBUG] Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2021-07-14 01:42:05,352 botocore.hooks [DEBUG] Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2021-07-14 01:42:05,352 botocore.hooks [DEBUG] Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2021-07-14 01:42:05,352 botocore.hooks [DEBUG] Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2021-07-14 01:42:05,353 botocore.hooks [DEBUG] Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2021-07-14 01:42:05,355 botocore.hooks [DEBUG] Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2021-07-14 01:42:05,355 botocore.hooks [DEBUG] Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2021-07-14 01:42:05,356 botocore.hooks [DEBUG] Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2021-07-14 01:42:05,356 botocore.hooks [DEBUG] Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2021-07-14 01:42:05,362 botocore.utils [DEBUG] IMDS ENDPOINT: http://169.254.169.254/
2021-07-14 01:42:05,369 botocore.credentials [DEBUG] Looking for credentials via: env
2021-07-14 01:42:05,369 botocore.credentials [DEBUG] Looking for credentials via: assume-role
2021-07-14 01:42:05,369 botocore.credentials [DEBUG] Looking for credentials via: assume-role-with-web-identity
2021-07-14 01:42:05,369 botocore.credentials [DEBUG] Looking for credentials via: sso
2021-07-14 01:42:05,369 botocore.credentials [DEBUG] Looking for credentials via: shared-credentials-file
2021-07-14 01:42:05,370 botocore.credentials [INFO] Found credentials in shared credentials file: ~/.aws/credentials
2021-07-14 01:42:05,370 botocore.loaders [DEBUG] Loading JSON file: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/botocore/data/endpoints.json
2021-07-14 01:42:05,377 botocore.hooks [DEBUG] Event choose-service-name: calling handler <function handle_service_name_alias at 0x7fd952f40b80>
2021-07-14 01:42:05,396 botocore.loaders [DEBUG] Loading JSON file: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/botocore/data/ec2/2016-11-15/service-2.json
2021-07-14 01:42:05,431 botocore.hooks [DEBUG] Event creating-client-class.ec2: calling handler <function add_generate_presigned_url at 0x7fd952ef15e0>
2021-07-14 01:42:05,434 botocore.endpoint [DEBUG] Setting ec2 timeout as (60, 60)
2021-07-14 01:42:05,435 botocore.loaders [DEBUG] Loading JSON file: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/botocore/data/_retry.json
2021-07-14 01:42:05,436 botocore.client [DEBUG] Registering retry handlers for service: ec2
2021-07-14 01:42:05,437 botocore.hooks [DEBUG] Event before-parameter-build.ec2.RequestSpotInstances: calling handler <bound method ParameterAlias.alias_parameter_in_call of <botocore.handlers.ParameterAlias object at 0x7fd952f754c0>>
2021-07-14 01:42:05,437 botocore.hooks [DEBUG] Event before-parameter-build.ec2.RequestSpotInstances: calling handler <function generate_idempotent_uuid at 0x7fd952f6bca0>
2021-07-14 01:42:05,437 botocore.hooks [DEBUG] Event before-call.ec2.RequestSpotInstances: calling handler <function inject_api_version_header_if_needed at 0x7fd952f73550>
2021-07-14 01:42:05,437 botocore.endpoint [DEBUG] Making request for OperationModel(name=RequestSpotInstances) with params: {'url_path': '/', 'query_string': '', 'method': 'POST', 'headers': {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 'User-Agent': 'Boto3/1.17.111 Python/3.8.3 Darwin/20.5.0 Botocore/1.20.111'}, 'body': {'Action': 'RequestSpotInstances', 'Version': '2016-11-15', 'LaunchSpecification.ImageId': 'ami-fake123', 'LaunchSpecification.InstanceType': 'c5.large'}, 'url': 'https://ec2.us-east-1.amazonaws.com/', 'context': {'client_region': 'us-east-1', 'client_config': <botocore.config.Config object at 0x7fd95433fac0>, 'has_streaming_input': False, 'auth_type': None}}
2021-07-14 01:42:05,437 botocore.hooks [DEBUG] Event request-created.ec2.RequestSpotInstances: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7fd95433f8e0>>
2021-07-14 01:42:05,438 botocore.hooks [DEBUG] Event choose-signer.ec2.RequestSpotInstances: calling handler <function set_operation_specific_signer at 0x7fd952f6bb80>
2021-07-14 01:42:05,438 botocore.auth [DEBUG] Calculating signature using v4 auth.
2021-07-14 01:42:05,438 botocore.auth [DEBUG] CanonicalRequest:
POST
/
content-type:application/x-www-form-urlencoded; charset=utf-8
host:ec2.us-east-1.amazonaws.com
x-amz-date:20210714T084205Z
content-type;host;x-amz-date
3a0356923c0fb50b7e823edf2c7924fe0487fbe6b1fb7d7b04d04ea77a0c9831
2021-07-14 01:42:05,438 botocore.auth [DEBUG] StringToSign:
AWS4-HMAC-SHA256
20210714T084205Z
20210714/us-east-1/ec2/aws4_request
94a1c1d7d9bea5c7fd73dc7196bcad42b6cf027ca73a254b90f3f231296d1a46
2021-07-14 01:42:05,438 botocore.auth [DEBUG] Signature:
6785ac91b3f7d34c3760da9e379e4f71d188252fffab84648bd523591d75538e
2021-07-14 01:42:05,438 botocore.endpoint [DEBUG] Sending http request: <AWSPreparedRequest stream_output=False, method=POST, url=https://ec2.us-east-1.amazonaws.com/, headers={'Content-Type': b'application/x-www-form-urlencoded; charset=utf-8', 'User-Agent': b'Boto3/1.17.111 Python/3.8.3 Darwin/20.5.0 Botocore/1.20.111', 'X-Amz-Date': b'20210714T084205Z', 'Authorization': b'AWS4-HMAC-SHA256 Credential=AKIAXAOUGHK4RVXMEFUC/20210714/us-east-1/ec2/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=6785ac91b3f7d34c3760da9e379e4f71d188252fffab84648bd523591d75538e', 'Content-Length': '138'}>
2021-07-14 01:42:05,439 botocore.httpsession [DEBUG] Certificate path: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/certifi/cacert.pem
2021-07-14 01:42:05,439 urllib3.connectionpool [DEBUG] Starting new HTTPS connection (1): ec2.us-east-1.amazonaws.com:443
2021-07-14 01:42:06,836 urllib3.connectionpool [DEBUG] https://ec2.us-east-1.amazonaws.com:443 "POST / HTTP/1.1" 400 None
2021-07-14 01:42:06,837 botocore.parsers [DEBUG] Response headers: {'x-amzn-RequestId': '4e759009-7884-46eb-bcf9-0a238087d593', 'Cache-Control': 'no-cache, no-store', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains', 'Content-Type': 'text/xml;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'vary': 'accept-encoding', 'Date': 'Wed, 14 Jul 2021 08:42:05 GMT', 'Connection': 'close', 'Server': 'AmazonEC2'}
2021-07-14 01:42:06,837 botocore.parsers [DEBUG] Response body:
b'<?xml version="1.0" encoding="UTF-8"?>\n<Response><Errors><Error><Code>InvalidAMIID.NotFound</Code><Message>The image id \'[ami-fake123]\' does not exist</Message></Error></Errors><RequestID>4e759009-7884-46eb-bcf9-0a238087d593</RequestID></Response>'
2021-07-14 01:42:06,846 botocore.hooks [DEBUG] Event needs-retry.ec2.RequestSpotInstances: calling handler <botocore.retryhandler.RetryHandler object at 0x7fd9543734f0>
2021-07-14 01:42:06,846 botocore.retryhandler [DEBUG] No retry needed.
Traceback (most recent call last):
File "eg.py", line 7, in <module>
client.request_spot_instances(LaunchSpecification=launch_specification)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/botocore/client.py", line 386, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/botocore/client.py", line 705, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidAMIID.NotFound) when calling the RequestSpotInstances operation: The image id '[ami-fake123]' does not exist
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
identifier "string" undefined? - c++ - Stack Overflow
You want to do #include <string> instead of string.h and then the type string lives in the std namespace, so you will need...
Read more >IBISCHK7 - IBIS Open Forum
The .ami format is tree-structure based where a parameter hierarchy is delineated by parentheses. Note that this user guide was first ...
Read more >The GNU Troff Manual
Note that identifiers longer than two characters with a closing bracket (' ] ') in its name can't be accessed with escape sequences...
Read more >Mathematical Markup Language (MathML) Version 3.0 ... - W3C
The primary MathML token element types are identifiers (e.g. variables or function names), numbers, and operators (including fences, such as parentheses, ...
Read more >MODULA-2 TABLE OF CONTENTS - Old Computers
The Strings Modules 237 ... which contains entries of reserved words standard identifiers, ... Period and. right parentheses for right index bracket.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
I’m glad to hear it’s working for you @markrogersjr. I agree it’s inacccurate. I will pass this information on to EC2. Since there isn’t anything for the Python SDK to do here, the information provided is correct but confusing, and it doesn’t impact the use of the SDK, I’ll close this issue and re-open one at the
aws/aws-sdk
repository to track it.