diff --git a/README.md b/README.md index f4eb63ac..0a8f2fa8 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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`). @@ -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. @@ -1754,7 +1752,6 @@ stepFunctions: End: true plugins: - serverless-step-functions - - serverless-pseudo-parameters ``` ### Retry Failure @@ -1794,7 +1791,6 @@ stepFunctions: End: true plugins: - serverless-step-functions - - serverless-pseudo-parameters ``` ### Parallel @@ -1835,7 +1831,6 @@ stepFunctions: End: true plugins: - serverless-step-functions - - serverless-pseudo-parameters ``` ### Catch Failure @@ -1878,7 +1873,6 @@ stepFunctions: End: true plugins: - serverless-step-functions - - serverless-pseudo-parameters ``` ### Choice @@ -1936,7 +1930,6 @@ stepFunctions: End: true plugins: - serverless-step-functions - - serverless-pseudo-parameters ``` ### Map diff --git a/lib/deploy/stepFunctions/compileAlarms.schema.js b/lib/deploy/stepFunctions/compileAlarms.schema.js index 93bb3619..ea5e0756 100644 --- a/lib/deploy/stepFunctions/compileAlarms.schema.js +++ b/lib/deploy/stepFunctions/compileAlarms.schema.js @@ -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({ diff --git a/lib/deploy/stepFunctions/compileAlarms.test.js b/lib/deploy/stepFunctions/compileAlarms.test.js index 6fad49fb..361b3749 100644 --- a/lib/deploy/stepFunctions/compileAlarms.test.js +++ b/lib/deploy/stepFunctions/compileAlarms.test.js @@ -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); + }); });