boto3
boto3 copied to clipboard
connect.list_tags_for_resource() and connect.tag_resource() reject phone number ARNs
Describe the bug
According to the connect.tag_resource() docs:
The supported resource types are users, routing profiles, queues, quick connects, contact flows, agent status, hours of operation, phone number, security profiles, and task templates.
Presumably these same resources can have their tags queried via connect.list_tags_for_resource()
However, the following code fails when using a valid phone number ARN (as does the equivalent test of connect.tag_resource()):
import boto3
print(boto3.__version__)
session = boto3.Session(profile_name='someprofile')
connect = session.client("connect")
print( connect.list_tags_for_resource(resourceArn="arn:aws:connect:<someregion>:<someaccount>:instance/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/phone-number/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")['tags'] )
Expected Behavior
a call to connect.list_tags_for_resource() should return a dict containing a tags object with all applied key/value tags (or {} when no tags)
a call to connect.tag_resource() should return None without error
Current Behavior
Any call to either connect.list_tags_for_resource() or connect.tag_resource() will fail with the following:
An error occurred (BadRequestException) when calling the ListTagsForResource operation: Invalid input resource arn
Reproduction Steps
connect.list_tags_for_resource() test:
import boto3
connect = boto3.client("connect")
print( connect.list_tags_for_resource(resourceArn="arn:aws:connect:<someregion>:<someaccount>:instance/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/phone-number/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")['tags'] )
connect.tag_resource() test:
import boto3
print(boto3.__version__)
connect = boto3.client("connect")
print( connect.list_tags_for_resource(resourceArn="arn:aws:connect:<someregion>:<someaccount>:instance/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/phone-number/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", tags={"somekey":"somevalue"}) )
Possible Solution
Does not appear to be a downstream issue; functions both work for queue resource types (I have not yet tested other types -- earlier today I had tested queue resources and they, also, failed but that appears to have been corrected sometime around 4pm CDT 2022-07-29)
Both function corollaries in the JS and GO SDKs appear to work fine for both phone numbers and queues (other resource types not tested).
Additional Information/Context
Context:
I am working on an automated deployment script that can autoprovision phone numbers (among other Amazon Connect resources). I need to access tags on phone numbers to allow proper identification during deployment or later environment synchronization.
A simple explanation is I want to have a list similar to:
[
{
"numberPrefix": "+1",
"type": "TOLL_FREE",
"flow": "Welcome"
}
{
"numberPrefix": "+1",
"type": "DID",
"flow": "Welcome"
}
{
"numberPrefix": "+44",
"type": "TOLL_FREE",
"flow": "Welcome2"
}
]
I would then, during the script, fetch all numbers from the target Connect instance, checking each for tags. Say that resulted in the following:
[
{
"PhoneNumber": "+15555551234",
"PhoneNumberType": "TOLL_FREE"
"...": "other fields returned by connect.list_phone_numbers()"
"tags": {
"flow": "Welcome"
}
}
]
I would now know I need to provision one UK (+44) toll-free number and one US (+1) DID number because the US toll-free number pointing to Welcome already exists. Without tags there is no way to associate numbers in Connect to the external list.
SDK version used
1.24.40 (have also tried 1.24.41 and 1.22.3 with no difference noted)
Environment details (OS name and version, etc.)
MacOS 12.4, python 3.9. Also tried using Lambda @python3.9, x86_64 with a boto3 1.24.40 layer - no change.
Hi @shawn-guenther thanks for reaching out. Are you using the same region in your boto3 environment as with the JS and Go SDKs? And are you using the same API call and ARNs with those SDKs?
Hi @tim-finnigan I am, indeed. All us-east-1, all against the same Connect instance and using the same queue and phone-number on both sets of tests.
@tim-finnigan In the interest of transparency: since I ran these tests last week it appears the entire API has shifted. I can no longer make any language work, or even the Connect API itself, when trying to retrieve phone number tags. So seemingly not restricted to boto.
Hi @shawn-guenther thanks for following up. The SDKs each use the same upstream service APIs (for example Connect TagResource) so there should be consistency between them. Did the issue only start occurring once you updated to a specific version of each SDK that you tried? And if so which versions?
I think we need more information in order to dig more into this. Could you share your debug logs (with any sensitive info redacted) by adding boto3.set_stream_logger('') to your script?
I had not used it in boto3 ever. I started writing this code at 1.22.3. Thought maybe it was boto, so tried on a Lambda with 1.24.40. Also upgraded local to 1.24.41. All same result.
The reason I ultimately opened the ticket here is that it was working under JS and GO, which both now fail. So the following seems to vindicate boto and point to the API undergoing changes.
This code run locally just now:
import boto3
print(boto3.__version__)
boto3.set_stream_logger('')
session = boto3.Session(profile_name='someprofile')
connect = session.client("connect")
print( connect.list_tags_for_resource(resourceArn="arn:aws:connect:us-east-1:111111111111:instance/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/phone-number/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")['tags'] )
resulted in this output:
1.24.41
2022-08-08 16:59:27,879 botocore.hooks [DEBUG] Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2022-08-08 16:59:27,881 botocore.hooks [DEBUG] Changing event name from before-call.apigateway to before-call.api-gateway
2022-08-08 16:59:27,882 botocore.hooks [DEBUG] Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2022-08-08 16:59:27,883 botocore.hooks [DEBUG] Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2022-08-08 16:59:27,883 botocore.hooks [DEBUG] Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2022-08-08 16:59:27,884 botocore.hooks [DEBUG] Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2022-08-08 16:59:27,885 botocore.hooks [DEBUG] Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2022-08-08 16:59:27,889 botocore.hooks [DEBUG] Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2022-08-08 16:59:27,890 botocore.hooks [DEBUG] Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2022-08-08 16:59:27,890 botocore.hooks [DEBUG] Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2022-08-08 16:59:27,890 botocore.hooks [DEBUG] Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2022-08-08 16:59:27,891 botocore.session [DEBUG] Setting config variable for profile to 'someprofile'
2022-08-08 16:59:27,993 botocore.utils [DEBUG] IMDS ENDPOINT: http://169.254.169.254/
2022-08-08 16:59:28,004 botocore.credentials [DEBUG] Skipping environment variable credential check because profile name was explicitly set.
2022-08-08 16:59:28,004 botocore.credentials [DEBUG] Looking for credentials via: assume-role
2022-08-08 16:59:28,004 botocore.credentials [DEBUG] Looking for credentials via: assume-role-with-web-identity
2022-08-08 16:59:28,004 botocore.credentials [DEBUG] Looking for credentials via: sso
2022-08-08 16:59:28,004 botocore.credentials [DEBUG] Looking for credentials via: shared-credentials-file
2022-08-08 16:59:28,005 botocore.credentials [DEBUG] Looking for credentials via: custom-process
2022-08-08 16:59:31,164 botocore.loaders [DEBUG] Loading JSON file: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/botocore/data/endpoints.json
2022-08-08 16:59:31,186 botocore.loaders [DEBUG] Loading JSON file: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/botocore/data/sdk-default-configuration.json
2022-08-08 16:59:31,187 botocore.hooks [DEBUG] Event choose-service-name: calling handler <function handle_service_name_alias at 0x7f9e283d4b80>
2022-08-08 16:59:31,396 botocore.loaders [DEBUG] Loading JSON file: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/botocore/data/connect/2017-08-08/service-2.json
2022-08-08 16:59:31,407 botocore.hooks [DEBUG] Event creating-client-class.connect: calling handler <function add_generate_presigned_url at 0x7f9e283565e0>
2022-08-08 16:59:31,409 botocore.endpoint [DEBUG] Setting connect timeout as (60, 60)
2022-08-08 16:59:31,416 botocore.loaders [DEBUG] Loading JSON file: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/botocore/data/_retry.json
2022-08-08 16:59:31,416 botocore.client [DEBUG] Registering retry handlers for service: connect
2022-08-08 16:59:31,417 botocore.hooks [DEBUG] Event before-parameter-build.connect.ListTagsForResource: calling handler <function generate_idempotent_uuid at 0x7f9e283ea0d0>
2022-08-08 16:59:31,418 botocore.hooks [DEBUG] Event before-call.connect.ListTagsForResource: calling handler <function add_recursion_detection_header at 0x7f9e283e8d30>
2022-08-08 16:59:31,418 botocore.hooks [DEBUG] Event before-call.connect.ListTagsForResource: calling handler <function inject_api_version_header_if_needed at 0x7f9e283ee940>
2022-08-08 16:59:31,418 botocore.endpoint [DEBUG] Making request for OperationModel(name=ListTagsForResource) with params: {'url_path': '/tags/arn%3Aaws%3Aconnect%3Aus-east-1%3A111111111111%3Ainstance%2Fxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%2Fphone-number%2Fxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'query_string': {}, 'method': 'GET', 'headers': {'User-Agent': 'Boto3/1.24.41 Python/3.9.0 Darwin/21.6.0 Botocore/1.27.41'}, 'body': b'', 'url': 'https://connect.us-east-1.amazonaws.com/tags/arn%3Aaws%3Aconnect%3Aus-east-1%3A111111111111%3Ainstance%2Fxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%2Fphone-number%2Fxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'context': {'client_region': 'us-east-1', 'client_config': <botocore.config.Config object at 0x7f9e28465a90>, 'has_streaming_input': False, 'auth_type': None}}
2022-08-08 16:59:31,418 botocore.hooks [DEBUG] Event request-created.connect.ListTagsForResource: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7f9e28465970>>
2022-08-08 16:59:31,419 botocore.hooks [DEBUG] Event choose-signer.connect.ListTagsForResource: calling handler <function set_operation_specific_signer at 0x7f9e283e8f70>
2022-08-08 16:59:31,419 botocore.auth [DEBUG] Calculating signature using v4 auth.
2022-08-08 16:59:31,419 botocore.auth [DEBUG] CanonicalRequest:
GET
/tags/arn%253Aaws%253Aconnect%253Aus-east-1%253A111111111111%253Ainstance%252Fxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%252Fphone-number%252Fxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
host:connect.us-east-1.amazonaws.com
x-amz-date:20220808T215931Z
x-amz-security-token:[sometoken]
host;x-amz-date;x-amz-security-token
[token]
2022-08-08 16:59:31,421 botocore.auth [DEBUG] StringToSign:
AWS4-HMAC-SHA256
20220808T215931Z
20220808/us-east-1/connect/aws4_request
[reqid]
2022-08-08 16:59:31,422 botocore.auth [DEBUG] Signature:
[reqid]
2022-08-08 16:59:31,422 botocore.hooks [DEBUG] Event request-created.connect.ListTagsForResource: calling handler <function add_retry_headers at 0x7f9e283f1040>
2022-08-08 16:59:31,422 botocore.endpoint [DEBUG] Sending http request: <AWSPreparedRequest stream_output=False, method=GET, url=https://connect.us-east-1.amazonaws.com/tags/arn%3Aaws%3Aconnect%3Aus-east-1%3A111111111111%3Ainstance%2Fxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%2Fphone-number%2Fxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, headers={'User-Agent': b'Boto3/1.24.41 Python/3.9.0 Darwin/21.6.0 Botocore/1.27.41', 'X-Amz-Date': b'20220808T215931Z', 'X-Amz-Security-Token': b'[sometoken], 'Authorization': b'AWS4-HMAC-SHA256 Credential=[ASIA]/20220808/us-east-1/connect/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token, Signature=[token]', 'amz-sdk-invocation-id': b'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'amz-sdk-request': b'attempt=1'}>
2022-08-08 16:59:31,426 botocore.httpsession [DEBUG] Certificate path: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/certifi/cacert.pem
2022-08-08 16:59:31,427 urllib3.connectionpool [DEBUG] Starting new HTTPS connection (1): connect.us-east-1.amazonaws.com:443
2022-08-08 16:59:31,788 urllib3.connectionpool [DEBUG] https://connect.us-east-1.amazonaws.com:443 "GET /tags/arn%3Aaws%3Aconnect%3Aus-east-1%3A111111111111%3Ainstance%2Fxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%2Fphone-number%2Fxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx HTTP/1.1" 400 41
2022-08-08 16:59:31,789 botocore.parsers [DEBUG] Response headers: {'Date': 'Mon, 08 Aug 2022 21:59:31 GMT', 'Content-Type': 'application/json', 'Content-Length': '41', 'Connection': 'keep-alive', 'x-amzn-RequestId': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': '*', 'x-amzn-ErrorType': 'BadRequestException', 'x-amz-apigw-id': '[id], 'X-Amzn-Trace-Id': 'Root=[root]'}
2022-08-08 16:59:31,789 botocore.parsers [DEBUG] Response body:
b'{"message": "Invalid input resource arn"}'
2022-08-08 16:59:31,793 botocore.hooks [DEBUG] Event needs-retry.connect.ListTagsForResource: calling handler <botocore.retryhandler.RetryHandler object at 0x7f9e383ad430>
2022-08-08 16:59:31,793 botocore.retryhandler [DEBUG] No retry needed.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 188, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "/Users/shawn.guenther/Source/scripts/get_connect_tags.py", line 7, in <module>
print( connect.list_tags_for_resource(resourceArn="arn:aws:connect:us-east-1:111111111111:instance/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/phone-number/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")['tags'] )
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/botocore/client.py", line 508, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/botocore/client.py", line 915, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (BadRequestException) when calling the ListTagsForResource operation: Invalid input resource arn
Hi @shawn-guenther thanks for following up. Since this occurs across SDKs then it relates to the service API as you mentioned, I can reach out to the Connect team for further investigation. You mentioned that the ARN you're using is valid, I would just try confirming that by using it in another command. Have you also tried reaching out to AWS Support? Opening a support case might help with expediting action on this.
Checking in as we haven't heard back in a while. As previously mentioned this is a service API issue rather than boto3 directly. I recommend reaching out through AWS Support for issues such as these to ensure they get escalated to the appropriate team. Alternatively we can also forward issues to internal teams on your behalf. Please let us know if you had any additional questions or feedback. I'm going to close this issue but will check back in if you respond.