Serverless-application-model: SAM Template AWS API GW logging.

Created on 28 Feb 2017  路  14Comments  路  Source: aws/serverless-application-model

I am using SAM Template to create API GW that would hook to a lambda function. Is there a way that I can specify the logs to be enabled for the stages ? Right now after the deploy I need to manually enable logs in the UI which is bit annoying.

typduplicate typfeature

Most helpful comment

To enable the CloudWatch Logs for AWS::Serverless::Api, you can set the LoggingLevel in the MethodSettings property.

Type: AWS::Serverless::Api
    Properties:
      MethodSettings:
        - LoggingLevel: INFO
          ResourcePath: '/*' # allows for logging on any resource
          HttpMethod: '*' # allows for logging on any method

All 14 comments

We are looking for this same functionality.

This is a miss from my perspective. Every deployment actually disables logging even if it was previously enabled.

Do we have any idea of a timeline for this to be addressed?

Makes sense. This is a popular feature ask. I will work to get this work prioritized.

+1

+1

+1

+1

+1

I've been told the only way to do this in an automated fashion via CFN is to not use SAM to define the API and stage. Feels like this violates the core tenet from CONTRIBUTING.md:

When defining your feature, keep in mind that one of the core tenets of AWS SAM is to keep it easy to use while allowing customers access to use more advanced components, should they so choose.

Access to more advanced components shouldn't be manual work in the console. This is more of a general comment but the more I use SAM, and the closer I get to production, the less I feel I can actually use it because it misses on simple things... like logging.

To ensure my deployments are repeatable I may just try to script this after my CFN templates are deployed.

@bradleyjames We are aware this is currently painful and are currently working on this feature. However, it is stuck in some discussions on how to move forward on part of the design. We do not have a date yet, but will reply here once we have something to share.

Please be patient with us as we sort some things out internally.

For anyone looking for a workaround I went ahead and scripted this. The template that creates the API outputs the ApiId at "AwsApiId".

...
Outputs:
  AwsApiId:
    Value: !Ref AwsApi
    Export:
      Name: !Sub ${AWS::StackName}-AwsApiId

After standing up the stack...

API_ID=`aws cloudformation describe-stacks --stack-name $STACK_NAME | jq '.Stacks[0].Outputs[] | select(.OutputKey == "AwsApiId") | .OutputValue' -r`

# http://docs.aws.amazon.com/cli/latest/reference/apigateway/update-stage.html
aws apigateway update-stage --rest-api-id $API_ID --stage-name  $STAGE_NAME --patch-operations \
  op=replace,path=/*/*/logging/dataTrace,value=true \
  op=replace,path=/*/*/logging/loglevel,value=Info \
  op=replace,path=/*/*/metrics/enabled,value=true 

@bradleyjames thank you for the workaround!

a little improvement, you can use --query to extract the API_ID

API_ID=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[0].Outputs[?OutputKey==`AwsApiId`].OutputValue --output text)

We created a parent task to track this. Please see #248 for updates.

Closing as duplicate of #248

To enable the CloudWatch Logs for AWS::Serverless::Api, you can set the LoggingLevel in the MethodSettings property.

Type: AWS::Serverless::Api
    Properties:
      MethodSettings:
        - LoggingLevel: INFO
          ResourcePath: '/*' # allows for logging on any resource
          HttpMethod: '*' # allows for logging on any method
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sanjP10 picture sanjP10  路  3Comments

rhboyd picture rhboyd  路  3Comments

yan12125 picture yan12125  路  3Comments

feinstein picture feinstein  路  3Comments

willdady picture willdady  路  3Comments