List functions paginator fails when given default region
See original GitHub issueDescribe the bug
I figured out that to customise the region name you use MasterRegion
(with the standard region name string) and FunctionVersion="ALL"
in the call to list_functions
, and hence to the paginate
call when using it with get_paginator
.
I expected the following code to work:
lambda_client = boto3.client("lambda", region_name=region.value)
response_iterator = lambda_client.get_paginator("list_functions").paginate(
MasterRegion=region.value, FunctionVersion="ALL"
)
functions = [
f
for f in resp["Functions"]
for resp in response_iterator
]
Instead I find that the default region (in my case, eu-west-1
) cannot be specified in this way. If you do, you get an empty list of functions
. Note that the HTTP status code is 200, so no error is being reported to debug.
>>> f = lambda_client.list_functions(MasterRegion="eu-west-1", FunctionVersion="ALL")
>>> lambda_client.meta.region_name
'eu-west-1'
>>> f
{'ResponseMetadata': {'RequestId': '3c03fde7-4063-45d8-949f-51ab8293ce69', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Fri, 27 May 2022 15:55:24 GMT', 'content-type': 'application/json', 'content-length': '34', 'connection': 'keep-alive', 'x-amzn-requestid': '3c03fde7-4063-45d8-949f-51ab8293ce69'}, 'RetryAttempts': 0}, 'Functions': []}
Compare:
>>> lambda_client = boto3.client("lambda", region_name="us-east-1")
>>> f = lambda_client.list_functions(MasterRegion="us-east-1", FunctionVersion="ALL")
>>> lambda_client.meta.region_name
'us-east-1'
>>> assert f["Functions"] != []
This means the default region must be taken into account when listing functions:
>>> boto3.DEFAULT_SESSION.region_name
'eu-west-1'
Expected Behavior
I’d expect all regions to be handled in the same way, so if you specify MasterRegion
and FunctionVersion
for the default session region, that would return functions not an empty list.
Current Behavior
If you specify MasterRegion
and FunctionVersion
for the default session region, it returns an empty list instead of functions.
Reproduction Steps
To reproduce you’d need:
- to have more than 1 region with a defined Lambda function.
- a
boto3
session with a default session region, specified in the local config typically, by~/.aws/config
with:
[default]
region = eu-west-1
First, set these variables according to your default session region:
default_region = boto3.DEFAULT_SESSION.region_name
different_region = "us-east-1"
The negative case (empty list), for the default region:
>>> lambda_client = boto3.client("lambda", region_name=default_region)
>>> f = lambda_client.list_functions(MasterRegion=default_region, FunctionVersion="ALL")
>>> assert f["Functions"] == []
The positive case (non-empty list), for the non-default region:
>>> lambda_client = boto3.client("lambda", region_name=different_region)
>>> f = lambda_client.list_functions(MasterRegion=different_region, FunctionVersion="ALL")
>>> assert f["Functions"] != []
Possible Solution
No response
Additional Information/Context
No response
SDK version used
1.21.43
Environment details (OS name and version, etc.)
Linux Mint 20.2 Uma (Ubuntu 20.04 base)
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Hi @tim-finnigan thanks for following up!
I was about to say no, but looking at it (I didn’t set this one up!) the description does indeed say it’s a “Lambda@Edge replica”. I’ve not come across this feature before, I guess it’s user error after all, I’m sorry.
The following code works, and especially since it’s a Friday I’m inclined to withdraw the issue after all
region_name
toboto3.client
as"eu-west-1"
gives aneu-west-1
functionregion_name
toboto3.client
(instead relying onboto3.DEFAULT_SESSION.region_name
) gives aneu-west-1
functionSo all is well after all. With apologies for any inconvenience, I seem to have got my wires crossed. 🤦♂️
Hi @lmmx I just had a chance to look into this again. In the documentation for
list_functions
it says this for MasterRegion:In your case were you using Lambda@Edge functions? Or does just setting
region_name
when establishing the client filter on the functions you want to retrieve?