Skip to content

Commit

Permalink
feat: add support for express workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
theburningmonk committed Dec 22, 2019
1 parent 0db7234 commit 9cfbc5f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
13 changes: 12 additions & 1 deletion lib/deploy/stepFunctions/compileIamRole.js
Expand Up @@ -5,7 +5,6 @@ const BbPromise = require('bluebird');
const path = require('path');
const { isIntrinsic, translateLocalFunctionNames, trimAliasFromLambdaArn } = require('../../utils/aws');


function getTaskStates(states) {
return _.flatMap(states, (state) => {
switch (state.Type) {
Expand Down Expand Up @@ -378,17 +377,29 @@ module.exports = {
compileIamRole() {
const customRolesProvided = [];
let iamPermissions = [];
let hasExpressWorkflow = false;
this.getAllStateMachines().forEach((stateMachineName) => {
const stateMachineObj = this.getStateMachine(stateMachineName);
customRolesProvided.push('role' in stateMachineObj);

const taskStates = getTaskStates(stateMachineObj.definition.States);
iamPermissions = iamPermissions.concat(getIamPermissions.bind(this)(taskStates));

if (stateMachineObj.type === 'EXPRESS') {
hasExpressWorkflow = true;
}
});
if (_.isEqual(_.uniq(customRolesProvided), [true])) {
return BbPromise.resolve();
}

if (hasExpressWorkflow) {
iamPermissions.push({
action: 'logs:CreateLogDelivery,logs:GetLogDelivery,logs:UpdateLogDelivery,logs:DeleteLogDelivery,logs:ListLogDeliveries,logs:PutResourcePolicy,logs:DescribeResourcePolicies,logs:DescribeLogGroups',
resource: '*',
});
}

const iamRoleStateMachineExecutionTemplate = this.serverless.utils.readFileSync(
path.join(__dirname,
'..',
Expand Down
12 changes: 10 additions & 2 deletions lib/deploy/stepFunctions/compileNotifications.js
Expand Up @@ -305,12 +305,20 @@ function* compileResources(stateMachineLogicalId, stateMachineName, notification
}
}

function validateConfig(serverless, stateMachineName, notificationsObj) {
function validateConfig(serverless, stateMachineName, stateMachineObj, notificationsObj) {
// no notifications defined at all
if (!_.isObject(notificationsObj)) {
return false;
}

if (stateMachineObj.type === 'EXPRESS') {
serverless.cli.consoleLog(
`State machine [${stateMachineName}] : notifications is not enabled on Express Workflows. `
+ '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.',
);
return false;
}

const { error } = Joi.validate(
notificationsObj, schema, { allowUnknown: false },
);
Expand All @@ -335,7 +343,7 @@ module.exports = {
const stateMachineName = stateMachineObj.name || name;
const notificationsObj = stateMachineObj.notifications;

if (!validateConfig(this.serverless, stateMachineName, notificationsObj)) {
if (!validateConfig(this.serverless, stateMachineName, stateMachineObj, notificationsObj)) {
return [];
}

Expand Down
17 changes: 17 additions & 0 deletions lib/deploy/stepFunctions/compileStateMachines.js
Expand Up @@ -96,6 +96,7 @@ module.exports = {
let DefinitionString;
let RoleArn;
let DependsOn = [];
let LoggingConfiguration;
const Tags = toTags(this.serverless.service.provider.tags);

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

if (stateMachineObj.type === 'EXPRESS' && stateMachineObj.loggingConfig) {
const Destinations = (stateMachineObj.loggingConfig.destinations || [])
.map(arn => ({
CloudWatchLogsLogGroup: {
LogGroupArn: arn,
},
}));
LoggingConfiguration = {
Level: stateMachineObj.loggingConfig.level,
IncludeExecutionData: stateMachineObj.loggingConfig.includeExecutionData,
Destinations,
};
}

const stateMachineLogicalId = this.getStateMachineLogicalId(stateMachineName,
stateMachineObj);
const stateMachineOutputLogicalId = this
Expand All @@ -191,6 +206,8 @@ module.exports = {
DefinitionString,
RoleArn,
Tags,
StateMachineType: stateMachineObj.type,
LoggingConfiguration,
},
DependsOn,
};
Expand Down
9 changes: 9 additions & 0 deletions lib/deploy/stepFunctions/compileStateMachines.schema.js
Expand Up @@ -26,13 +26,20 @@ const dependsOn = Joi.alternatives().try(
Joi.array().items(Joi.string()),
);

const loggingConfig = Joi.object().keys({
level: Joi.string().valid('ALL', 'ERROR', 'FATAL', 'OFF').default('OFF'),
includeExecutionData: Joi.boolean().default(false),
destinations: Joi.array().items(arn),
});

const id = Joi.string();
const tags = Joi.object();
const name = Joi.string();
const events = Joi.array();
const alarms = Joi.object();
const notifications = Joi.object();
const useExactVersion = Joi.boolean().default(false);
const type = Joi.string().valid('STANDARD', 'EXPRESS').default('STANDARD');

const schema = Joi.object().keys({
id,
Expand All @@ -45,6 +52,8 @@ const schema = Joi.object().keys({
tags,
alarms,
notifications,
type,
loggingConfig,
});

module.exports = schema;

0 comments on commit 9cfbc5f

Please sign in to comment.