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

Fix bug when using websocket events with functions with custom roles #5880

Merged
merged 1 commit into from
Mar 4, 2019
Merged
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
33 changes: 19 additions & 14 deletions lib/plugins/aws/package/compile/events/websockets/lib/api.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@ module.exports = {
}, },
}); });


// insert policy that allows functions to postToConnection const defaultRoleResource = this.serverless.service.provider.compiledCloudFormationTemplate
const websocketsPolicy = { .Resources[this.provider.naming.getRoleLogicalId()];
Effect: 'Allow',
Action: ['execute-api:ManageConnections'], if (defaultRoleResource) {
Resource: ['arn:aws:execute-api:*:*:*/@connections/*'], // insert policy that allows functions to postToConnection
}; const websocketsPolicy = {

Effect: 'Allow',
this.serverless.service.provider.compiledCloudFormationTemplate Action: ['execute-api:ManageConnections'],
.Resources[this.provider.naming.getRoleLogicalId()] Resource: ['arn:aws:execute-api:*:*:*/@connections/*'],
.Properties };
.Policies[0]
.PolicyDocument this.serverless.service.provider.compiledCloudFormationTemplate
.Statement .Resources[this.provider.naming.getRoleLogicalId()]
.push(websocketsPolicy); .Properties
.Policies[0]
.PolicyDocument
.Statement
.push(websocketsPolicy);
}


return BbPromise.resolve(); return BbPromise.resolve();
}, },
Expand Down
13 changes: 13 additions & 0 deletions lib/plugins/aws/package/compile/events/websockets/lib/api.test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -77,4 +77,17 @@ describe('#compileApi()', () => {
}, },
}); });
})); }));

it('should NOT add the websockets policy if role resource does not exist', () => {
awsCompileWebsocketsEvents.serverless.service.provider.compiledCloudFormationTemplate
.Resources = {};

return awsCompileWebsocketsEvents
.compileApi().then(() => {
const resources = awsCompileWebsocketsEvents.serverless.service.provider
.compiledCloudFormationTemplate.Resources;

expect(resources[roleLogicalId]).to.deep.equal(undefined);
});
});
}); });