4

I'm trying to use the Serverless framework to create a Lambda which is invoked when a client connects to a websocket API Gateway. AWS CloudFormation is creating the Lambda functions that are defined but the websocket API Gateway isn't being created.

After attempting to write my own (which didn't work) I resorted to copy and pasting the examples I've found on Serverless docs into a freshly created serverless folder just to see if it would work - it didn't, and I can't find anyone else who seems to have had a similar problem.


So far I've tried the simple and extended methods documented here (which is what the example code is based on): https://serverless.com/framework/docs/providers/aws/events/websocket/

And I've also tried to follow this blog, which also resulted in the Lambda creation but not an API Gateway. https://serverless.com/blog/api-gateway-websockets-example/

Here's my serverless.yml file. It deploys as I would expect, apart from the API Gateway:

service: temp
provider:
  name: aws
  runtime: nodejs8.10
  region: eu-west-2

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

Here is the serverless deploy -v output:

$ serverless deploy -v
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
CloudFormation - CREATE_IN_PROGRESS - AWS::CloudFormation::Stack - temp-dev
CloudFormation - CREATE_IN_PROGRESS - AWS::S3::Bucket - ServerlessDeploymentBucket
CloudFormation - CREATE_IN_PROGRESS - AWS::S3::Bucket - ServerlessDeploymentBucket
CloudFormation - CREATE_COMPLETE - AWS::S3::Bucket - ServerlessDeploymentBucket
CloudFormation - CREATE_COMPLETE - AWS::CloudFormation::Stack - temp-dev
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (386 B)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - temp-dev
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - DefaultLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - DefaultLogGroup
CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - DefaultLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_COMPLETE - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - DefaultLambdaFunction
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - DefaultLambdaFunction
CloudFormation - CREATE_COMPLETE - AWS::Lambda::Function - DefaultLambdaFunction
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Version - DefaultLambdaVersionY0DDREbM8apFqgW7p0WqFe2SjYB4Wt7O63fYPiljU
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Version - DefaultLambdaVersionY0DDREbM8apFqgW7p0WqFe2SjYB4Wt7O63fYPiljU
CloudFormation - CREATE_COMPLETE - AWS::Lambda::Version - DefaultLambdaVersionY0DDREbM8apFqgW7p0WqFe2SjYB4Wt7O63fYPiljU
CloudFormation - UPDATE_COMPLETE_CLEANUP_IN_PROGRESS - AWS::CloudFormation::Stack - temp-dev
CloudFormation - UPDATE_COMPLETE - AWS::CloudFormation::Stack - temp-dev
Serverless: Stack update finished...
Service Information
service: temp
stage: dev
region: eu-west-2
stack: temp-dev
api keys:
  None
endpoints:
  None
functions:
  default: temp-dev-default
layers:
  None

Stack Outputs
DefaultLambdaFunctionQualifiedArn: arn:aws:lambda:eu-west-2:[redacted]:function:temp-dev-default:3
ServerlessDeploymentBucketName: temp-dev-serverlessdeploymentbucket-[redacted]

If anyone can shed some light on this as I may be completely missing something obvious, I'd be grateful.

2
  • Do you get any error when deploying ? Have you tried serverless deploy --verbose to see if you can get more hints ? What exactly is wrong with the deployment ? Nothing is created in API gateway ? Commented Apr 24, 2019 at 23:59
  • @Hugo I don't get any errors. It fails silently. I've just added the output of serverless deploy -v to the question. Yes, nothing is created in API Gateway like you would expect. Commented Apr 25, 2019 at 10:07

2 Answers 2

7

I had the exact same issue and for me the solution was to indent route properly like this:

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

So basically change:

- websocket: 
  route: $default

to:

- websocket: 
    route: $default
Sign up to request clarification or add additional context in comments.

1 Comment

Oh wow, I had this exact same issue. There was no warning output from severless deploy and the difference is quite subtle as the dash before the parent makes things look indented at a glance
2

After going through literally everything related to Serverless I realised my Serverless version is not the most recent one (don't ask me how that happened, I ran yarn add serverless to get a project specific version of it yesterday)

Instead, the version was 1.35 and thus had no support for API Gateway websockets. Perhaps I had installed it globally at a previous point and neglected to remove it from my global npm packages...

The fact it was failing to recognise the tags silently did not help the debugging process and I might - when I get chance - contribute to the project by adding a validation run on the Serverless.yml files so unsupported options are flagged in the console.

As it was, running npm install -g serverless@latest fixed the problem and now the API Gateway gets deployed correctly.

Thank you Alex and Hugo for responding!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.