pythonamazon-web-servicesaws-lambdaboto3amazon-connect

aws connect search_available_phone_numbers API for python does not work


I am trying to use the available phone number API in order to claim and attach a contact flow. I tried following the documentation provided by AWS for python.

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/connect.html#Connect.Client.search_available_phone_numbers

when I try to use it, it gives the following error

Exception thrown: 'Connect' object has no attribute 'search_available_phone_numbers'"

client = boto3.client('connect')
response = client.search_available_phone_numbers(
        TargetArn='arn:aws:connect:us-east-1:**********:instance/**********/contact-flow/....',
        PhoneNumberCountryCode='US',
        PhoneNumberType='TOLL_FREE'
    )

NOTE: I tried using other APIs like create user, Associate lambda, and Associate LEX. All those worked except the one I .

Thanks in advance


Solution

  • You will need to create a layer for boto3 pointing to the latest version of the package that includes the search_available_phone_numbers API that you are trying to call and add that layer to the lambda.

    The AWS Lambda service supports up to python 3.9 runtimes currently, and it's associated boto3 package version points to version 1.20.32 (https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html)

    You can double check this within your own lambda function on the console if you added print(boto3.__version__) after your boto3 import. As of right now, the python sdk (boto3) docs references version 1.25.4 and hence there will be quite a few features and updates in the docs that are not reflected by the package currently built into the AWS Lambda service.

    Hope this adds some clarity to your question!