serverless-plugin-log-subscription icon indicating copy to clipboard operation
serverless-plugin-log-subscription copied to clipboard

[Bug] - stage not being set correctly

Open codezninja opened this issue 2 years ago • 0 comments

When deploying the following config I noticed that for api gateway execution logs the stage, even though being set via cli options is not being set correctly and it is being set as default stage which is dev. I believe these lines might need to reference something else to support stage being set via cli options. Note: I've pruned account id and alias information

  • https://github.com/dougmoscrop/serverless-plugin-log-subscription/blob/053c02ed53c23b3421cfe6cff6f3c7225a37ff17/serverless-plugin-log-subscription.js#L135
  • https://github.com/dougmoscrop/serverless-plugin-log-subscription/blob/053c02ed53c23b3421cfe6cff6f3c7225a37ff17/serverless-plugin-log-subscription.js#L171
  • https://github.com/dougmoscrop/serverless-plugin-log-subscription/blob/053c02ed53c23b3421cfe6cff6f3c7225a37ff17/serverless-plugin-log-subscription.js#L208

serverlessy.yml

service: test

plugins:
  - serverless-offline
  - serverless-plugin-log-subscription

provider:
  name: aws
  runtime: nodejs16.x
  region: us-east-1
  timeout: 30
  logs:
    restApi:
      roleManagedExternally: true
      accessLogging: true
      fullExecutionData: true
      level: INFO
      format: '{
          "accountId": "$context.accountId",
          "apiGwId": "$context.apiId",
          "apiGwRequestTime": "$context.requestTime",
          "apiGwRequestId": "$context.requestId",
          "apiGwExtRequestId":"$context.extendedRequestId",
          "httpMethod": "$context.httpMethod",
          "path": "$context.path",
          "resourcePath": "$context.resourcePath",
          "status": "$context.status",
          "protocol": "$context.protocol",
          "responseLatency": "$context.responseLatency",
          "caller": "$context.identity.caller",
          "callerIp": "$context.identity.sourceIp",
          "iamUser": "$context.identity.user",
          "userArn": "$context.identity.userArn",
          "correlationUserAgent": "$context.identity.userAgent",
          "apiKey": "$context.identity.apiKey",
          "apiKeyId": "$context.identity.apiKeyId",
          "apiError": "$context.error.message",
          "responseType": "$context.error.responseType",
          "validationError": "$context.error.validationErrorString",
          "lambdaError": "$context.integrationErrorMessage",
          "lambdaStatus": "$context.integrationStatus"
        }'

  logRetentionInDays: 7
  versionFunctions: false
  apiGateway:
    metrics: true
    minimumCompressionSize: 1024
custom:
  logSubscription:
    enabled: true
    destinationArn: arn:aws:logs:${self:provider.region}:xxxxxxxxx:destination:xxxxxxxxx-cloudwatch-lambda-destination-${self:provider.region}
    apiGatewayLogs: true
  prune:
    automatic: true
    number: 3

shell command

SLS_DEBUG=* sls package --stage=int1

cloudformation-template-update-stack.json

    "ApiGatewayExecutionLogGroupSubscriptionFilter": {
      "Type": "AWS::Logs::SubscriptionFilter",
      "Properties": {
        "DestinationArn": "arn:aws:logs:us-east-1:xxxxxxxxx:destination:xxxxxxxxx-cloudwatch-lambda-destination-us-east-1",
        "FilterPattern": "",
        "LogGroupName": {
          "Fn::Sub": "API-Gateway-Execution-Logs_${ApiGatewayRestApi}/dev"
        }
      },
      "DependsOn": [
        "ApiGatewayDeployment1688389544858"
      ]
    }
  },

Version

# sls -version
Framework Core: 3.28.1 (local)
Plugin: 6.2.3
SDK: 4.3.2

serverless-plugin-log-subscription@^2.2.0

Current workaround

Set stage on provider setting with ${opt:stage}

provider:
  name: aws
  runtime: nodejs16.x
  region: us-east-1
  timeout: 30
  stage: ${opt:stage}

codezninja avatar Jul 03 '23 14:07 codezninja