Reputation: 91
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.
Upvotes: 4
Views: 2680
Reputation: 131
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
Upvotes: 7
Reputation: 91
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!
Upvotes: 2