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

Invalid format in AccessLogSettings produced for websocket Api GW stage #7038

Closed
henhal opened this issue Dec 3, 2019 · 6 comments
Closed

Comments

@henhal
Copy link

henhal commented Dec 3, 2019

Bug Report

Description

I have a websocket API gateway which has been deployed multiple times successfully. Now, all of a sudden the stack fails due to the Format of the AccessLogSettings in my AWS::ApiGatewayV2::Stage resource called WebsocketsDeploymentStage including $context.status which is not a valid context variable for websocket API:s, only REST API:s.
I don't know if this is due to a recent change in SLS or in AWS, but this API was deployed many times before without issues.

The following context variables are not supported: [$context.status] (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException; Request ID: aa19bd81-9ef4-4182-89cd-29ae21d46fa1)

My serverless.yml file simply contains one or more functions with websocket events:

functions:
  MyWebSocketFunction:
    handler: websocket.handler
    events:
      - websocket:
          route: $connect 

This automatically causes SLS to create CF resources WebsocketsDeploymentStage etc:

  "WebsocketsDeploymentStage": {
      "Type": "AWS::ApiGatewayV2::Stage",
      "Properties": {
        "ApiId": {
          "Ref": "WebsocketsApi"
        },
        "DeploymentId": {
          "Ref": "WebsocketsDeployment1575366683940"
        },
        "StageName": "dev",
        "Description": "Serverless Websockets",
        "AccessLogSettings": {
          "DestinationArn": {
            "Fn::Sub": "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${WebsocketsLogGroup}"
          },
          "Format": "$context.identity.sourceIp $context.identity.caller $context.identity.user [$context.requestTime] \"$context.eventType $context.routeKey $context.connectionId\" $context.status $context.requestId"
        },
        "DefaultRouteSettings": {
          "DataTraceEnabled": true,
          "LoggingLevel": "INFO"
        }
      }
    },

I managed to temporarily resolve this by overriding the WebsocketsDeploymentStage resource to override the AccessLogSettings.Format property and remove $context.status from the value:

resources:
  Resources:
    ...
    WebsocketsDeploymentStage:
      # Overriding faulty format generated by SLS
      Properties:
        AccessLogSettings:
          Format: "$context.identity.sourceIp $context.identity.caller $context.identity.user [$context.requestTime] \"$context.eventType $context.routeKey $context.connectionId\" $context.requestId"

Then the stack was deployed just fine. But it seems like SLS is applying a default format string for the deployment stage which is not accepted by CF due to the use of the unsupported variable $context.status.

Similar or dependent issues:

@henhal
Copy link
Author

henhal commented Dec 3, 2019

Update: I checked the deployment we made about one week back and it also has the same $context.status format, but was accepted by AWS API Gateway. This makes me think that AWS changed something during the past few days, no longer accepting the $context.status property for websocket logs. If so, I assume SLS simply needs to adapt to this fact?

@henhal
Copy link
Author

henhal commented Dec 3, 2019

I went to find where this was located in the code and found that it was already fixed in d1537f7#diff-0b32a7aba4382097ae2219b301f674d2

When will this make it into a release?

@medikoo
Copy link
Contributor

medikoo commented Dec 3, 2019

When will this make it into a release?

Sorry about delay. It'll be released first thing tomorrow CET morning.

@medikoo
Copy link
Contributor

medikoo commented Dec 3, 2019

Closing as duplicate of #7016

@medikoo medikoo closed this as completed Dec 3, 2019
@Gr8z
Copy link

Gr8z commented Dec 4, 2019

I am still having this issue in 1.59

Logs:

Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service BotBindSocketAPI.zip file to S3 (1.62 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
...................
Serverless: Operation failed!
Serverless: View the full error output: https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stack/detail?stackId=arn%3Aaws%3Acloudformation%3Aus-east-1%3A093373140224%3Astack%2FBotBindSocketAPI-development%2F2c2e8cb0-edc1-11e9-b592-0eb40de15aba

  Serverless Error ---------------------------------------

  An error occurred: WebsocketsDeploymentStage - The following context variables are not supported: [$context.status] (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException; Request ID: 56719d2c-f316-4835-86ac-15ea266e7af3).
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          win32
     Node Version:              10.15.2
     Framework Version:         1.59.0
     Plugin Version:            3.2.5
     SDK Version:               2.2.1
     Components Core Version:   1.1.2
     Components CLI Version:    1.4.0

@medikoo
Copy link
Contributor

medikoo commented Dec 4, 2019

I am still having this issue in 1.59

Are you sure you're using CF template as generated by 1.59.0, and not e.g. one generated with older version ?

In v1.59.0, there's no mention of $context.status in part that handles Websocket logs -> https://github.com/serverless/serverless/blob/v1.59.0/lib/plugins/aws/package/compile/events/websockets/lib/stage.js#L62-L69

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

No branches or pull requests

3 participants