Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ plugins:

Specify your state machine definition using Amazon States Language in a `definition` statement in serverless.yml. You can use CloudFormation intrinsic functions such as `Ref` and `Fn::GetAtt` to reference Lambda functions, SNS topics, SQS queues and DynamoDB tables declared in the same `serverless.yml`. Since `Ref` returns different things (ARN, ID, resource name, etc.) depending on the type of CloudFormation resource, please refer to [this page](https://theburningmonk.com/cloudformation-ref-and-getatt-cheatsheet/) to see whether you need to use `Ref` or `Fn::GetAtt`.

Alternatively, you can also provide the raw ARN, or SQS queue URL, or DynamoDB table name as a string. If you need to construct the ARN by hand, then we recommend to use the [serverless-pseudo-parameters](https://www.npmjs.com/package/serverless-pseudo-parameters) plugin together to make your life easier.
Alternatively, you can also provide the raw ARN, or SQS queue URL, or DynamoDB table name as a string. If you need to construct the ARN by hand using pseudo-parameters such as `${AWS::Region}` or `${AWS::AccountId}`, use the `Fn::Sub` CloudFormation intrinsic function directly — no extra plugins required.

In addition, if you want to reference a DynamoDB table managed by an external CloudFormation Stack, as long as that table name is exported as an output from that stack, it can be referenced by importing it using `Fn::ImportValue`. See the `ddbtablestepfunc` Step Function definition below for an example.

Expand Down Expand Up @@ -181,7 +181,6 @@ stepFunctions:

plugins:
- serverless-step-functions
- serverless-pseudo-parameters
```

In the example above, notice that we used `Fn::GetAtt: [hello, Arn]` to get the ARN for the `hello` function defined earlier. This means you don't have to know how the `Serverless` framework converts these local names to CloudFormation logical IDs (e.g. `hello-world` becomes `HelloDashworldLambdaFunction`).
Expand Down Expand Up @@ -1003,7 +1002,6 @@ functions:

plugins:
- serverless-step-functions
- serverless-pseudo-parameters
```

Please note that those are the API keys names, not the actual values. Once you deploy your service, the value of those API keys will be auto generated by AWS and printed on the screen for you to use. The values can be concealed from the output with the --conceal deploy option.
Expand Down Expand Up @@ -1754,7 +1752,6 @@ stepFunctions:
End: true
plugins:
- serverless-step-functions
- serverless-pseudo-parameters
```

### Retry Failure
Expand Down Expand Up @@ -1794,7 +1791,6 @@ stepFunctions:
End: true
plugins:
- serverless-step-functions
- serverless-pseudo-parameters
```

### Parallel
Expand Down Expand Up @@ -1835,7 +1831,6 @@ stepFunctions:
End: true
plugins:
- serverless-step-functions
- serverless-pseudo-parameters
```

### Catch Failure
Expand Down Expand Up @@ -1878,7 +1873,6 @@ stepFunctions:
End: true
plugins:
- serverless-step-functions
- serverless-pseudo-parameters
```

### Choice
Expand Down Expand Up @@ -1936,7 +1930,6 @@ stepFunctions:
End: true
plugins:
- serverless-step-functions
- serverless-pseudo-parameters
```

### Map
Expand Down
6 changes: 6 additions & 0 deletions lib/deploy/stepFunctions/compileAlarms.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ const arn = Joi.alternatives().try(
),
),
}),
Joi.object().keys({
'Fn::Sub': Joi.alternatives().try(
Joi.string(),
Joi.array().items(Joi.string(), Joi.object()),
),
}),
);

const topics = Joi.object().keys({
Expand Down
27 changes: 27 additions & 0 deletions lib/deploy/stepFunctions/compileAlarms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,4 +630,31 @@ describe('#compileAlarms', () => {
expect(resources.StateMachineBeta1ExecutionsFailedAlarm.Properties.Period).to.equal(3600);
expect(consoleLogSpy.callCount).equal(0);
});

it('should support Fn::Sub in alarm topics', () => {
serverless.service.stepFunctions = {
stateMachines: {
myStateMachine1: {
name: 'stateMachineBeta1',
definition: { StartAt: 'A', States: { A: { Type: 'Pass', End: true } } },
alarms: {
topics: {
alarm: { 'Fn::Sub': 'arn:aws:sns:${AWS::Region}:${AWS::AccountId}:foo-sns-topic' },
},
metrics: ['executionsFailed'],
},
},
},
};

serverlessStepFunctions.compileAlarms();
const resources = serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources;

expect(resources).to.have.property('StateMachineBeta1ExecutionsFailedAlarm');
validateCloudWatchAlarm(resources.StateMachineBeta1ExecutionsFailedAlarm);
expect(resources.StateMachineBeta1ExecutionsFailedAlarm.Properties.AlarmActions)
.to.deep.equal([{ 'Fn::Sub': 'arn:aws:sns:${AWS::Region}:${AWS::AccountId}:foo-sns-topic' }]);
expect(consoleLogSpy.callCount).equal(0);
});
});
Loading