Created
July 13, 2023 09:02
-
-
Save nicksnell/e28829cbfacaf4ad68063adf26e9e3d9 to your computer and use it in GitHub Desktop.
Find all the lambda resources in a given cloudformation stack (AWS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import os | |
import boto3 | |
boto3.setup_default_session(profile_name=os.environ.get("AWS_PROFILE", "default")) | |
def discover_lambdas(stack_name): | |
cf = boto3.client("cloudformation") | |
paginator = cf.get_paginator("list_stack_resources") | |
lambdas = [] | |
token = None | |
result = paginator.paginate(PaginationConfig={"NextToken": token}, StackName=stack_name) | |
for page in result: | |
for resource in page["StackResourceSummaries"]: | |
if resource["ResourceType"] == "AWS::Lambda::Function": | |
lambdas.append(resource["PhysicalResourceId"]) | |
return lambdas | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description="Find all lambdas in a stack") | |
parser.add_argument("--stack", help="The stack to search for lambdas", required=True) | |
args = parser.parse_args() | |
lambdas = discover_lambdas(args.stack) | |
for l in lambdas: | |
print(f"λ {l}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment