boto3 icon indicating copy to clipboard operation
boto3 copied to clipboard

Please improve docstring on how default region_name and other arguments are set around client using env variables or within Lambda execution

Open iamtennislover opened this issue 3 years ago • 3 comments

Please fill out the sections below to help us address your issue.

What issue did you see ? After looking into https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html#boto3.session.Session.client, i couldn't find how region_name defaults depending upon variable environment variables. This is especially useful to understand since when we try to initialize the boto3.client within an AWS Lambda function, we don't need to pass region_name explicitly if we want to use the local region

So that way users instead of doing this boto3.client("sts", region_name=os.environ["AWS_REGION"]) will simply do this boto3.client("sts")

I believe https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html doesn't mention it but testing locally, Lambda env variable contains AWS_DEFAULT_REGION which is what gets used by boto3 to default the region_name

Steps to reproduce N/A

Debug logs N/A

iamtennislover avatar Dec 15 '21 19:12 iamtennislover

Hi @iamtennislover, thanks for reaching out. Could you elaborate a bit more on exactly which section of the documentation you would like to see updated? If you have any specific suggestions for how the wording or content could be improved that would also be helpful.

tim-finnigan avatar Dec 15 '21 23:12 tim-finnigan

Hi, i would think the source of https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html#boto3.session.Session.client

def client(self,...
        """

        :type region_name: string
        :param region_name: The name of the region associated with the client.
+            Defaults to OS environment variable of AWS_DEFAULT_REGION or from the config (https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html)

that way, any user looking at the source can refer to the docstring and understand how the default region_name is set without having to look into the source code. but if the region_name default is setup in more complex way, maybe having a guide and referencing it in docstring can also help

iamtennislover avatar Dec 20 '21 01:12 iamtennislover

https://github.com/boto/boto3/blob/cc80410348897ee112789c2f31af3b1a7ff61302/boto3/session.py#L109

if we make changes in this line, will it work ? I am new to community, it would be great if u can help. @iamtennislover @tim-finnigan

aayushharwani-aidash avatar May 14 '22 17:05 aayushharwani-aidash