0

I have a lambda function within AWS based off the clear-lambda-storage application at . There is code that is as follows:

from argparse import Namespace
from clear_lambda_storage import remove_old_lambda_versions


def clear_lambda_storage(event, context):
    remove_old_lambda_versions(Namespace(token_key_id=None, token_secret=None, regions=None, profile=None, num_to_keep=3, function_names=["insertName"]))
    return "Successful clean! 🗑 ✅"

With the function_names argument I want to have a list of names of all the lambda functions in the account - is there any way I can do this besides manually hardcoding them (so that if a new lambda function is added, the list is updated).

1 Answer 1

1

use the SDK. IN ptyhon, this is boto3, and so one of these commands, probably https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lambda.html#Lambda.Client.list_functions

Sign up to request clarification or add additional context in comments.

4 Comments

but this returns a maximum of 50 functions per call - to get all the lambda functions would I need to keep calling it multiple times?
Not quite - you need to use Pagination. The NextMarker (string) tag gives you the ability to page along the results. It technically is multiple calls, but can be done with the same client declaration in your code.
sorry what do you mean by same client declaration? do you have an example
With the SDKs (ie boto3) you declare a client for connecting to a given service. fn_client = boto3.client("lambda") as long as you are not re-declaring a client, you can make multiple fn_client.list_functions() calls with the NextMarker token as a starting point in order to page through all of them. Doing so in a Loop is one method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.