serverless-plugin-tracing
serverless-plugin-tracing copied to clipboard
Support for API Gateway
AWS supports X-Ray for API Gateways: https://aws.amazon.com/de/blogs/aws/apigateway-xray/ It would be great to configure the stage property via this serverless plugin.
I could not find any hints if cloudformation supports it yet. At least it is not documented.
Looks like it has landed - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-tracingenabled
Note: that cloudformation cannot update tracingEnabled
for existing stack
so I had to integrate bash script in my pipeline:
#!/bin/bash
REST_API_ID=$(aws cloudformation describe-stack-resource --region $AWS_REGION --stack-name $STACK_NAME --logical-resource-id ApiGatewayRestApi | jq --raw-output .StackResourceDetail.PhysicalResourceId)
echo "Ensure tracing is enabled for api gateway stage: $REST_API_ID / $STAGE"
TRACING_ENABLED=$(aws apigateway get-stage --region $AWS_REGION --rest-api-id $REST_API_ID --stage-name $STAGE | jq --raw-output .tracingEnabled)
if [ "$TRACING_ENABLED" == 'false' ]; then
aws apigateway update-stage --region $AWS_REGION --rest-api-id $REST_API_ID --stage-name $STAGE --patch-operations op=replace,path=/tracingEnabled,value=true
fi
LAMBDA_IDS=$(aws cloudformation describe-stack-resources --region $AWS_REGION --stack-name $STACK_NAME | jq --raw-output -c '.StackResources | map(select( .ResourceType | contains("AWS::Lambda::Function"))) | map(.PhysicalResourceId) | .[]')
while IFS= read -r LAMBDA_ID; do
echo "Ensure tracing is enabled for lambda function: $LAMBDA_ID"
TRACING_MODE=$(aws lambda get-function-configuration --region $AWS_REGION --function-name $LAMBDA_ID | jq --raw-output .TracingConfig.Mode)
if [ "$TRACING_MODE" == 'PassThrough' ]; then
aws lambda update-function-configuration --region $AWS_REGION --function-name $LAMBDA_ID --tracing-config Mode=Active
fi
done <<< "$LAMBDA_IDS"