Skip to content

Commit cf5345a

Browse files
docs: updated docs to explain ref'ng local function name
1 parent b9525e5 commit cf5345a

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ plugins:
6767
6868
## Setup
6969
70-
Specifies your statemachine 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`.
70+
Specifies your statemachine 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`.
7171

7272
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.
7373

@@ -99,7 +99,7 @@ stepFunctions:
9999
HelloWorld1:
100100
Type: Task
101101
Resource:
102-
Fn::GetAtt: [HelloLambdaFunction, Arn]
102+
Fn::GetAtt: [hello, Arn]
103103
End: true
104104
dependsOn: CustomIamRole
105105
tags:
@@ -123,7 +123,7 @@ stepFunctions:
123123
HelloWorld2:
124124
Type: Task
125125
Resource:
126-
Fn::GetAtt: [HelloLambdaFunction, Arn]
126+
Fn::GetAtt: [hello, Arn]
127127
End: true
128128
dependsOn:
129129
- DynamoDBTable
@@ -140,6 +140,10 @@ plugins:
140140
- serverless-pseudo-parameters
141141
```
142142

143+
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`).
144+
145+
However, if you prefer to work with logical IDs, you can. You can also express the above `Fn::GetAtt` function as `Fn::GetAtt: [HelloLambdaFunction, Arn]`. If you're unfamiliar with the convention the `Serverless` framework uses, then the easiest thing to do is to first run `sls package` then look in the `.serverless` folder for the generated CloudFormation template. Here you can find the logical resource names for the functions you want to reference.
146+
143147
### Adding a custom name for a stateMachine
144148

145149
In case you need to interpolate a specific stage or service layer variable as the
@@ -691,7 +695,7 @@ functions:
691695
HelloWorld1:
692696
Type: Task
693697
Resource:
694-
Fn::GetAtt: [HelloLambdaFunction, Arn]
698+
Fn::GetAtt: [hello, Arn]
695699
End: true
696700
697701
@@ -1008,7 +1012,7 @@ stepFunctions:
10081012
FirstState:
10091013
Type: Task
10101014
Resource:
1011-
Fn::GetAtt: [HelloLambdaFunction, Arn]
1015+
Fn::GetAtt: [hello, Arn]
10121016
Next: wait_using_seconds
10131017
wait_using_seconds:
10141018
Type: Wait
@@ -1029,7 +1033,7 @@ stepFunctions:
10291033
FinalState:
10301034
Type: Task
10311035
Resource:
1032-
Fn::GetAtt: [HelloLambdaFunction, Arn]
1036+
Fn::GetAtt: [hello, Arn]
10331037
End: true
10341038
plugins:
10351039
- serverless-step-functions
@@ -1053,7 +1057,7 @@ stepFunctions:
10531057
HelloWorld:
10541058
Type: Task
10551059
Resource:
1056-
Fn::GetAtt: [HelloLambdaFunction, Arn]
1060+
Fn::GetAtt: [hello, Arn]
10571061
Retry:
10581062
- ErrorEquals:
10591063
- HandledError
@@ -1134,7 +1138,7 @@ stepFunctions:
11341138
HelloWorld:
11351139
Type: Task
11361140
Resource:
1137-
Fn::GetAtt: [HelloLambdaFunction, Arn]
1141+
Fn::GetAtt: [hello, Arn]
11381142
Catch:
11391143
- ErrorEquals: ["HandledError"]
11401144
Next: CustomErrorFallback
@@ -1183,7 +1187,7 @@ stepFunctions:
11831187
FirstState:
11841188
Type: Task
11851189
Resource:
1186-
Fn::GetAtt: [Hello1LambdaFunction, Arn]
1190+
Fn::GetAtt: [hello, Arn]
11871191
Next: ChoiceState
11881192
ChoiceState:
11891193
Type: Choice
@@ -1198,20 +1202,20 @@ stepFunctions:
11981202
FirstMatchState:
11991203
Type: Task
12001204
Resource:
1201-
Fn::GetAtt: [Hello2LambdaFunction, Arn]
1205+
Fn::GetAtt: [hello2, Arn]
12021206
Next: NextState
12031207
SecondMatchState:
12041208
Type: Task
12051209
Resource:
1206-
Fn::GetAtt: [Hello3LambdaFunction, Arn]
1210+
Fn::GetAtt: [hello3, Arn]
12071211
Next: NextState
12081212
DefaultState:
12091213
Type: Fail
12101214
Cause: "No Matches!"
12111215
NextState:
12121216
Type: Task
12131217
Resource:
1214-
Fn::GetAtt: [Hello4LambdaFunction, Arn]
1218+
Fn::GetAtt: [hello4, Arn]
12151219
End: true
12161220
plugins:
12171221
- serverless-step-functions

0 commit comments

Comments
 (0)