Skip to content

Instantly share code, notes, and snippets.

@joekiller
Last active June 25, 2020 19:09
Show Gist options
  • Save joekiller/ffddfe4942c09d4c9e5bc507aacc1076 to your computer and use it in GitHub Desktop.
Save joekiller/ffddfe4942c09d4c9e5bc507aacc1076 to your computer and use it in GitHub Desktop.
Enable Lambda X-Ray on all functions via AWS CLI
#!/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
@joekiller
Copy link
Author

@gvasquez-waypoint I agree, IAM can have a slight lag on associate policy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment