question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

List functions paginator fails when given default region

See original GitHub issue

Describe 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:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lmmxcommented, Jun 24, 2022

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

>>> lambda_client = boto3.client("lambda", region_name="us-east-1")
>>> response_iterator = lambda_client.get_paginator("list_functions").paginate()
>>> next(f for resp in response_iterator for f in resp["Functions"])["FunctionArn"].split(":")[3]
'us-east-1
  • Again but passing region_name to boto3.client as "eu-west-1" gives an eu-west-1 function
  • Again but not passing region_name to boto3.client (instead relying on boto3.DEFAULT_SESSION.region_name) gives an eu-west-1 function

So all is well after all. With apologies for any inconvenience, I seem to have got my wires crossed. 🤦‍♂️

0reactions
tim-finnigancommented, Jun 20, 2022

Hi @lmmx I just had a chance to look into this again. In the documentation for list_functions it says this for MasterRegion:

MasterRegion (string) – For Lambda@Edge functions, the Amazon Web Services Region of the master function. For example, us-east-1 filters the list of functions to only include Lambda@Edge functions replicated from a master function in US East (N. Virginia). If specified, you must set FunctionVersion to ALL .

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Paginators — Boto3 Docs 1.26.32 documentation - AWS
Paginators are a feature of boto3 that act as an abstraction over the process of iterating over an entire result set of a...
Read more >
List Lambda functions using an AWS SDK
Functions ; } /// <summary> /// Uses a Lambda paginator to retrieve the list of functions in the /// AWS Region with which...
Read more >
Using the AWS SDK for Go V2 with AWS Services
To construct a paginator for a supported operation, use the New<OperationName>Paginator function. Paginator construct functions take the service ...
Read more >
Stripe API reference – curl
By default, the Stripe API Docs demonstrate using curl to interact with the API over HTTP ... Codes in the 4xx range indicate...
Read more >
FunctionsManagement (Oracle Cloud Infrastructure Java SDK - 3.1.0)
Retrieves a function. FunctionsManagementPaginators · getPaginators(). Gets the pre-configured paginators available for list operations in this service which ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found