Skip to content

Commit 3470f4c

Browse files
authored
Merge pull request awslabs#199 from roblaks/master
Paginate ListFunctions calls to ensure all functions are found
2 parents 2a9b970 + c2e38d2 commit 3470f4c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Lambda/FindEniMappings/findEniAssociations

+10-4
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,17 @@ echo "Found "${ENI}" with "$Subnet" using Security Groups" ${SortedSGs[@]}
6666
echo "Searching for Lambda function versions using "$Subnet" and Security Groups" ${SortedSGs[@]}"..."
6767

6868
# Get all the Lambda functions in an account that are using the same subnet, including versions
69-
Response="$(aws lambda list-functions --function-version ALL --region ${REGION} --output json --query 'Functions[?VpcConfig!=`null` && VpcConfig.SubnetIds!=`[]`] | [].{Arn:FunctionArn, Subnets:VpcConfig.SubnetIds, SecurityGroups: VpcConfig.SecurityGroupIds} | [?contains(Subnets, `'$Subnet'`) == `true`]')"
7069
Functions=()
71-
for row in $(echo $Response | jq -c -r '.[]')
72-
do
73-
Functions+=(${row})
70+
Response="$(aws lambda list-functions --function-version ALL --max-items 1000 --region ${REGION} --output json --query '{"NextToken": NextToken, "VpcConfigsByFunction": Functions[?VpcConfig!=`null` && VpcConfig.SubnetIds!=`[]`] | [].{Arn:FunctionArn, Subnets:VpcConfig.SubnetIds, SecurityGroups: VpcConfig.SecurityGroupIds} | [?contains(Subnets, `'$Subnet'`) == `true`] }')"
71+
# Find functions using the same subnet and security group as target ENI. Use paginated calls to enumerate all functions.
72+
while : ; do
73+
NextToken=$(echo $Response | jq '.NextToken')
74+
for row in $(echo $Response | jq -c -r '.VpcConfigsByFunction[]')
75+
do
76+
Functions+=(${row})
77+
done
78+
[[ $NextToken != "null" ]] || break
79+
Response="$(aws lambda list-functions --function-version ALL --max-items 1000 --starting-token $NextToken --region ${REGION} --output json --query '{"NextToken": NextToken, "VpcConfigsByFunction": Functions[?VpcConfig!=`null` && VpcConfig.SubnetIds!=`[]`] | [].{Arn:FunctionArn, Subnets:VpcConfig.SubnetIds, SecurityGroups: VpcConfig.SecurityGroupIds} | [?contains(Subnets, `'$Subnet'`) == `true`] }')"
7480
done
7581
# check if we got any functions with this subnet at all
7682
if [ $(echo "${#Functions[@]}") -eq 0 ]

0 commit comments

Comments
 (0)