Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/deploy/events/apiGateway/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ module.exports = {
stateMachineObj,
http,
),
...(http && http.timeoutInMillis && { TimeoutInMillis: http.timeoutInMillis }),
};

let responses;
Expand Down
15 changes: 15 additions & 0 deletions lib/deploy/events/apiGateway/methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ describe('#methods()', () => {
.to.equal('\'*\'');
});

it('should set TimeoutInMillis when timeoutInMillis is provided',
() => {
const integration = serverlessStepFunctions.getMethodIntegration('stateMachine', undefined, {
timeoutInMillis: 10000,
}).Properties.Integration;
expect(integration.TimeoutInMillis).to.equal(10000);
});

it('should not set TimeoutInMillis when timeoutInMillis is not provided',
() => {
const integration = serverlessStepFunctions
.getMethodIntegration('stateMachine').Properties.Integration;
expect(integration.TimeoutInMillis).to.equal(undefined);
});

it('should change passthroughBehavior and action when action is set',
() => {
expect(serverlessStepFunctions.getMethodIntegration('stateMachine', 'custom', {
Expand Down
7 changes: 7 additions & 0 deletions lib/deploy/events/apiGateway/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ module.exports = {
http.authorizer = this.getAuthorizer(http, stateMachineName);
}

if (!http.timeoutInMillis) {
const providerTimeout = _.get(this.serverless.service.provider.apiGateway, 'timeoutInMillis');
if (providerTimeout) {
http.timeoutInMillis = providerTimeout;
}
}

if (http.cors) {
http.cors = this.getCors(http);

Expand Down
68 changes: 68 additions & 0 deletions lib/deploy/events/apiGateway/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,4 +822,72 @@ describe('#httpValidate()', () => {
expect(validated.events[0].http.cors.origin).to.equal('*');
expect(validated.events[0].http.cors.maxAge).to.equal(86400);
});

it('should pass timeoutInMillis from the http event', () => {
serverlessStepFunctions.serverless.service.stepFunctions = {
stateMachines: {
first: {
events: [
{
http: {
method: 'POST',
path: '/foo/bar',
timeoutInMillis: 10000,
},
},
],
},
},
};

const validated = serverlessStepFunctions.httpValidate();
expect(validated.events[0].http.timeoutInMillis).to.equal(10000);
});

it('should use provider.apiGateway.timeoutInMillis as default when not set on event', () => {
serverlessStepFunctions.serverless.service.provider.apiGateway = {
timeoutInMillis: 15000,
};
serverlessStepFunctions.serverless.service.stepFunctions = {
stateMachines: {
first: {
events: [
{
http: {
method: 'POST',
path: '/foo/bar',
},
},
],
},
},
};

const validated = serverlessStepFunctions.httpValidate();
expect(validated.events[0].http.timeoutInMillis).to.equal(15000);
});

it('should prefer event-level timeoutInMillis over provider default', () => {
serverlessStepFunctions.serverless.service.provider.apiGateway = {
timeoutInMillis: 15000,
};
serverlessStepFunctions.serverless.service.stepFunctions = {
stateMachines: {
first: {
events: [
{
http: {
method: 'POST',
path: '/foo/bar',
timeoutInMillis: 5000,
},
},
],
},
},
};

const validated = serverlessStepFunctions.httpValidate();
expect(validated.events[0].http.timeoutInMillis).to.equal(5000);
});
});
Loading