Skip to content

Commit 6ebbad2

Browse files
feat: add support for express workflows
Closes #281
1 parent 8c03e05 commit 6ebbad2

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

lib/deploy/stepFunctions/compileIamRole.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const BbPromise = require('bluebird');
55
const path = require('path');
66
const { isIntrinsic, translateLocalFunctionNames, trimAliasFromLambdaArn } = require('../../utils/aws');
77

8-
98
function getTaskStates(states) {
109
return _.flatMap(states, (state) => {
1110
switch (state.Type) {
@@ -378,17 +377,29 @@ module.exports = {
378377
compileIamRole() {
379378
const customRolesProvided = [];
380379
let iamPermissions = [];
380+
let hasExpressWorkflow = false;
381381
this.getAllStateMachines().forEach((stateMachineName) => {
382382
const stateMachineObj = this.getStateMachine(stateMachineName);
383383
customRolesProvided.push('role' in stateMachineObj);
384384

385385
const taskStates = getTaskStates(stateMachineObj.definition.States);
386386
iamPermissions = iamPermissions.concat(getIamPermissions.bind(this)(taskStates));
387+
388+
if (stateMachineObj.type === 'EXPRESS') {
389+
hasExpressWorkflow = true;
390+
}
387391
});
388392
if (_.isEqual(_.uniq(customRolesProvided), [true])) {
389393
return BbPromise.resolve();
390394
}
391395

396+
if (hasExpressWorkflow) {
397+
iamPermissions.push({
398+
action: 'logs:CreateLogDelivery,logs:GetLogDelivery,logs:UpdateLogDelivery,logs:DeleteLogDelivery,logs:ListLogDeliveries,logs:PutResourcePolicy,logs:DescribeResourcePolicies,logs:DescribeLogGroups',
399+
resource: '*',
400+
});
401+
}
402+
392403
const iamRoleStateMachineExecutionTemplate = this.serverless.utils.readFileSync(
393404
path.join(__dirname,
394405
'..',

lib/deploy/stepFunctions/compileNotifications.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,20 @@ function* compileResources(stateMachineLogicalId, stateMachineName, notification
305305
}
306306
}
307307

308-
function validateConfig(serverless, stateMachineName, notificationsObj) {
308+
function validateConfig(serverless, stateMachineName, stateMachineObj, notificationsObj) {
309309
// no notifications defined at all
310310
if (!_.isObject(notificationsObj)) {
311311
return false;
312312
}
313313

314+
if (stateMachineObj.type === 'EXPRESS') {
315+
serverless.cli.consoleLog(
316+
`State machine [${stateMachineName}] : notifications is not enabled on Express Workflows. `
317+
+ 'Please see https://docs.aws.amazon.com/step-functions/latest/dg/concepts-standard-vs-express.html for difference between Step Functions Standard and Express Workflow.',
318+
);
319+
return false;
320+
}
321+
314322
const { error } = Joi.validate(
315323
notificationsObj, schema, { allowUnknown: false },
316324
);
@@ -335,7 +343,7 @@ module.exports = {
335343
const stateMachineName = stateMachineObj.name || name;
336344
const notificationsObj = stateMachineObj.notifications;
337345

338-
if (!validateConfig(this.serverless, stateMachineName, notificationsObj)) {
346+
if (!validateConfig(this.serverless, stateMachineName, stateMachineObj, notificationsObj)) {
339347
return [];
340348
}
341349

lib/deploy/stepFunctions/compileStateMachines.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ module.exports = {
9696
let DefinitionString;
9797
let RoleArn;
9898
let DependsOn = [];
99+
let LoggingConfiguration;
99100
const Tags = toTags(this.serverless.service.provider.tags);
100101

101102
const { error } = Joi.validate(stateMachineObj, schema, { allowUnknown: false });
@@ -181,6 +182,20 @@ module.exports = {
181182
_.forEach(stateMachineTags, tag => Tags.push(tag));
182183
}
183184

185+
if (stateMachineObj.type === 'EXPRESS' && stateMachineObj.loggingConfig) {
186+
const Destinations = (stateMachineObj.loggingConfig.destinations || [])
187+
.map(arn => ({
188+
CloudWatchLogsLogGroup: {
189+
LogGroupArn: arn,
190+
},
191+
}));
192+
LoggingConfiguration = {
193+
Level: stateMachineObj.loggingConfig.level,
194+
IncludeExecutionData: stateMachineObj.loggingConfig.includeExecutionData,
195+
Destinations,
196+
};
197+
}
198+
184199
const stateMachineLogicalId = this.getStateMachineLogicalId(stateMachineName,
185200
stateMachineObj);
186201
const stateMachineOutputLogicalId = this
@@ -191,6 +206,8 @@ module.exports = {
191206
DefinitionString,
192207
RoleArn,
193208
Tags,
209+
StateMachineType: stateMachineObj.type,
210+
LoggingConfiguration,
194211
},
195212
DependsOn,
196213
};

lib/deploy/stepFunctions/compileStateMachines.schema.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,20 @@ const dependsOn = Joi.alternatives().try(
2626
Joi.array().items(Joi.string()),
2727
);
2828

29+
const loggingConfig = Joi.object().keys({
30+
level: Joi.string().valid('ALL', 'ERROR', 'FATAL', 'OFF').default('OFF'),
31+
includeExecutionData: Joi.boolean().default(false),
32+
destinations: Joi.array().items(arn),
33+
});
34+
2935
const id = Joi.string();
3036
const tags = Joi.object();
3137
const name = Joi.string();
3238
const events = Joi.array();
3339
const alarms = Joi.object();
3440
const notifications = Joi.object();
3541
const useExactVersion = Joi.boolean().default(false);
42+
const type = Joi.string().valid('STANDARD', 'EXPRESS').default('STANDARD');
3643

3744
const schema = Joi.object().keys({
3845
id,
@@ -45,6 +52,8 @@ const schema = Joi.object().keys({
4552
tags,
4653
alarms,
4754
notifications,
55+
type,
56+
loggingConfig,
4857
});
4958

5059
module.exports = schema;

0 commit comments

Comments
 (0)