Last active
June 25, 2020 19:09
-
-
Save joekiller/ffddfe4942c09d4c9e5bc507aacc1076 to your computer and use it in GitHub Desktop.
Enable Lambda X-Ray on all functions via AWS CLI
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
#!/bin/bash | |
fns=($(aws lambda list-functions --query "Functions[].FunctionName" --output text)) | |
GrantWrite () { | |
aws iam attach-role-policy --policy-arn arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess --role-name $(ROLE=$(aws lambda get-function --function-name $1 --query "Configuration.Role" --output text);echo ${ROLE##*/}) | |
} | |
XRay () { | |
aws lambda update-function-configuration --function-name $1 --tracing-config Mode=Active >/dev/null && echo $1 OK || (GrantWrite $1; aws lambda update-function-configuration --function-name $1 --tracing-config Mode=Active > /dev/null && echo $1 OK || echo $1 FAILED) | |
} | |
for f in ${fns[@]}; do XRay $f; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@gvasquez-waypoint I agree, IAM can have a slight lag on associate policy