You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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`.
19
23
20
24
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.
@@ -47,7 +51,7 @@ stepFunctions:
47
51
HelloWorld1:
48
52
Type: Task
49
53
Resource:
50
-
Ref: HelloLambdaFunction
54
+
Fn::GetAtt: [HelloLambdaFunction, Arn]
51
55
End: true
52
56
dependsOn: CustomIamRole
53
57
tags:
@@ -71,7 +75,7 @@ stepFunctions:
71
75
HelloWorld2:
72
76
Type: Task
73
77
Resource:
74
-
Ref: HelloLambdaFunction
78
+
Fn::GetAtt: [HelloLambdaFunction, Arn]
75
79
End: true
76
80
dependsOn:
77
81
- DynamoDBTable
@@ -89,6 +93,7 @@ plugins:
89
93
```
90
94
91
95
### Adding a custom name for a stateMachine
96
+
92
97
In case you need to interpolate a specific stage or service layer variable as the
93
98
stateMachines name you can add a `name` property to your yaml.
94
99
@@ -111,6 +116,7 @@ plugins:
111
116
```
112
117
113
118
### Adding a custom logical id for a stateMachine
119
+
114
120
You can use a custom logical id that is only unique within the stack as opposed to the name that needs to be unique globally. This can make referencing the state machine easier/simpler because you don't have to duplicate the interpolation logic everywhere you reference the state machine.
115
121
116
122
```yml
@@ -135,6 +141,7 @@ plugins:
135
141
You can then `Ref: SendMessageStateMachine` in various parts of CloudFormation or serverless.yml
136
142
137
143
#### Depending on another logical id
144
+
138
145
If your state machine depends on another resource defined in your `serverless.yml` then you can add a `dependsOn` field to the state machine `definition`. This would add the `DependsOn`clause to the generated CloudFormation template.
139
146
140
147
This `dependsOn` field can be either a string, or an array of strings.
@@ -152,6 +159,7 @@ stepFunctions:
152
159
```
153
160
154
161
#### CloudWatch Alarms
162
+
155
163
It's common practice to want to monitor the health of your state machines and be alerted when something goes wrong. You can either:
156
164
157
165
* do this using the [serverless-plugin-aws-alerts](https://github.com/ACloudGuru/serverless-plugin-aws-alerts), which lets you configure custom CloudWatch Alarms against the various metrics that Step Functions publishes.
@@ -186,6 +194,7 @@ You can configure how the CloudWatch Alarms should treat missing data:
186
194
For more information, please refer to the [official documentation](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html#alarms-and-missing-data).
187
195
188
196
The generated CloudWatch alarms would have the following configurations:
Please keep this gotcha in mind if you want to reference the `name` from the `resources` section. To generate Logical ID for CloudFormation, the plugin transforms the specified name in serverless.yml based on the following scheme.
222
232
223
-
-Transform a leading character into uppercase
224
-
-Transform `-` into Dash
225
-
-Transform `_` into Underscore
233
+
* Transform a leading character into uppercase
234
+
* Transform `-` into Dash
235
+
* Transform `_` into Underscore
226
236
227
237
If you want to use variables system in name statement, you can't put the variables as a prefix like this:`${self:service}-${opt:stage}-myStateMachine` since the variables are transformed within Output section, as a result, the reference will be broken.
228
238
@@ -243,11 +253,14 @@ resources:
243
253
```
244
254
245
255
## Events
256
+
246
257
### API Gateway
258
+
247
259
To create HTTP endpoints as Event sources for your StepFunctions statemachine
248
260
249
261
#### Simple HTTP Endpoint
250
-
This setup specifies that the hello statemachine should be run when someone accesses the API gateway at hello via a GET request.
262
+
263
+
This setup specifies that the hello state machine should be run when someone accesses the API gateway at hello via a GET request.
251
264
252
265
Here's an example:
253
266
@@ -261,6 +274,7 @@ stepFunctions:
261
274
method: GET
262
275
definition:
263
276
```
277
+
264
278
#### HTTP Endpoint with Extended Options
265
279
266
280
Here You can define an POST endpoint for the path posts/create.
@@ -293,6 +307,7 @@ provider:
293
307
functions:
294
308
...
295
309
```
310
+
296
311
If your application has many nested paths, you might also want to break them out into smaller services.
297
312
298
313
However, Cloudformation will throw an error if we try to generate an existing path resource. To avoid that, we reference the resource ID:
@@ -444,10 +459,27 @@ stepFunctions:
444
459
Ref: ApiGatewayAuthorizer # or hard-code Authorizer ID
445
460
```
446
461
462
+
#### LAMBDA_PROXY request template
463
+
464
+
The plugin generates default body mapping templates for `application/json` and `application/x-www-form-urlencoded` content types. The default template would pass the request body as input to the state machine. If you need access to other contextual information about the HTTP request such as headers, path parameters, etc. then you can also use the `lambda_proxy` request template like this:
465
+
466
+
```yml
467
+
stepFunctions:
468
+
stateMachines:
469
+
hello:
470
+
events:
471
+
- http:
472
+
path: posts/create
473
+
method: POST
474
+
request:
475
+
template: lambda_proxy
476
+
```
477
+
478
+
This would generate the normal LAMBDA_PROXY template used for API Gateway integration with Lambda functions.
447
479
448
480
#### Customizing request body mapping templates
449
481
450
-
The plugin generates default body mapping templates for `application/json` and `application/x-www-form-urlencoded` content types. If you'd like to add more content types or customize the default ones, you can do so by including your custom [API Gateway request mapping template](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html) in `serverless.yml` like so:
482
+
If you'd like to add content types or customize the default templates, you can do so by including your custom [API Gateway request mapping template](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html) in `serverless.yml` like so:
451
483
452
484
```yml
453
485
stepFunctions:
@@ -472,13 +504,13 @@ stepFunctions:
472
504
```
473
505
474
506
#### Send request to an API
507
+
475
508
You can input an value as json in request body, the value is passed as the input value of your statemachine
You can specify a list of API keys to be used by your service Rest API by adding an apiKeys array property to the provider object in serverless.yml. You'll also need to explicitly specify which endpoints are private and require one of the api keys to be included in the request by adding a private boolean property to the http event object you want to set as private. API Keys are created globally, so if you want to deploy your service to different stages make sure your API key contains a stage variable as defined below. When using API keys, you can optionally define usage plan quota and throttle, using usagePlan object.
483
515
484
516
Here's an example configuration for setting API keys for your service Rest API:
@@ -519,7 +551,7 @@ functions:
519
551
HelloWorld1:
520
552
Type: Task
521
553
Resource:
522
-
Ref: HelloLambdaFunction
554
+
Fn::GetAtt: [HelloLambdaFunction, Arn]
523
555
End: true
524
556
525
557
@@ -533,6 +565,7 @@ Please note that those are the API keys names, not the actual values. Once you d
533
565
Clients connecting to this Rest API will then need to set any of these API keys values in the x-api-key header of their request. This is only necessary for functions where the private property is set to true.
534
566
535
567
### Schedule
568
+
536
569
The following config will attach a schedule event and causes the stateMachine `crawl` to be called every 2 hours. The configuration allows you to attach multiple schedules to the same stateMachine. You can either use the `rate` or `cron` syntax. Take a look at the [AWS schedule syntax documentation](http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html) for more details.
537
570
538
571
```yaml
@@ -592,9 +625,10 @@ events:
592
625
- schedule:
593
626
rate: rate(2 hours)
594
627
role: arn:aws:iam::xxxxxxxx:role/yourRole
595
-
628
+
```
596
629
597
630
### CloudWatch Event
631
+
598
632
## Simple event definition
599
633
600
634
This will enable your Statemachine to be called by an EC2 event rule.
@@ -733,20 +767,20 @@ You can specify tags on each state machine. Additionally any global tags (specif
733
767
## Command
734
768
735
769
### deploy
770
+
736
771
Run `sls deploy`, the defined Stepfunctions are deployed.
0 commit comments