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

Add support for externally managed websocket event authorizers #12344

Open
wants to merge 2 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion docs/providers/aws/events/websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ functions:
handler: handler.auth
```

Or, if your authorizer function is not managed by this service, you can provide an arn instead:
You also can provide an arn:

```yml
functions:
Expand All @@ -129,6 +129,19 @@ functions:
authorizer: arn:aws:lambda:us-east-1:1234567890:function:auth
```

If your authorizer is externally managed (not run by this service), you can use `managedExternally` to skip permission creation:
```yml
functions:
connectHandler:
handler: handler.connectHandler
events:
- websocket:
route: $connect
authorizer:
arn: arn:aws:lambda:us-east-1:1234567890:function:auth
managedExternally: true
```

By default, the `identitySource` property is set to `route.request.header.Auth`, meaning that your request must include the auth token in the `Auth` header of the request. You can overwrite this by specifying your own `identitySource` configuration:

```yml
Expand Down
1 change: 1 addition & 0 deletions lib/plugins/aws/package/compile/events/websockets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class AwsCompileWebsockets {
name: { $ref: '#/definitions/functionName' },
arn: { $ref: '#/definitions/awsArn' },
identitySource: { type: 'array', items: { type: 'string' } },
managedExternally: { type: 'boolean' },
},
anyOf: [{ required: ['name'] }, { required: ['arn'] }],
additionalProperties: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const resolveLambdaTarget = require('../../../../../utils/resolve-lambda-target'
module.exports = {
compilePermissions() {
this.validated.events.forEach((event) => {
if (event.authorizer && event.authorizer.managedExternally) return;

const websocketApiId = this.provider.getApiGatewayWebsocketApiId();
const lambdaLogicalId = this.provider.naming.getLambdaLogicalId(event.functionName);
const functionObj = this.serverless.service.getFunction(event.functionName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ module.exports = {
} else {
websocketObj.authorizer.identitySource = event.websocket.authorizer.identitySource;
}

if (event.websocket.authorizer.managedExternally){
websocketObj.authorizer.managedExternally = true;
}
}
events.push(websocketObj);
// dealing with the simplified string representation
Expand Down