Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for API Gateway #18

Open
chgerkens opened this issue Sep 7, 2018 · 2 comments
Open

Support for API Gateway #18

chgerkens opened this issue Sep 7, 2018 · 2 comments

Comments

@chgerkens
Copy link

chgerkens commented Sep 7, 2018

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.

@chgerkens chgerkens reopened this Sep 7, 2018
@thejuan
Copy link

thejuan commented Nov 28, 2018

Looks like it has landed - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-tracingenabled

@floydspace
Copy link

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants