Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3bc6cee

Browse files
committed
Merge pull request 41
2 parents 1647176 + bc1df9a commit 3bc6cee

37 files changed

+599
-73
lines changed

‎code/lab-4/state-machine.asl.json

Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,67 @@
3636
"Next": "ChargeFare"
3737
},
3838
"ChargeFare": {
39-
"Comment": "Add comment...",
4039
"Type": "Task",
41-
"Resource": "${PaymentChargeFunctionArn}",
42-
"Next": "CustomerAccountCredit",
43-
"Catch": [{
44-
"ErrorEquals": [
45-
"PaymentAuthException",
46-
"PaymentChargeException"
47-
],
48-
"Next": "SetFareStatusFailed",
49-
"ResultPath": "$.chargeError"
50-
}]
40+
"Resource": "arn:aws:states:::lambda:invoke",
41+
"OutputPath": "$.Payload",
42+
"Parameters": {
43+
"Payload.$": "$",
44+
"FunctionName": "${PaymentChargeFunctionArn}"
45+
},
46+
"Retry": [
47+
{
48+
"ErrorEquals": [
49+
"Lambda.ServiceException",
50+
"Lambda.AWSLambdaException",
51+
"Lambda.SdkClientException"
52+
],
53+
"IntervalSeconds": 2,
54+
"MaxAttempts": 6,
55+
"BackoffRate": 2
56+
}
57+
],
58+
"Next": "CreditCustomerAccount",
59+
"Catch": [
60+
{
61+
"ErrorEquals": [
62+
"PaymentAuthException",
63+
"PaymentChargeException"
64+
],
65+
"ResultPath": "$.chargeError",
66+
"Next": "SetFareStatusFailed"
67+
}
68+
]
5169
},
52-
"CustomerAccountCredit": {
53-
"Comment": "Add comment...",
70+
"CreditCustomerAccount": {
5471
"Type": "Task",
55-
"Resource": "${AccountCreditFunctionArn}",
72+
"Resource": "arn:aws:states:::lambda:invoke",
73+
"OutputPath": "$.Payload",
74+
"Parameters": {
75+
"Payload.$": "$",
76+
"FunctionName": "${AccountCreditFunctionArn}"
77+
},
78+
"Retry": [
79+
{
80+
"ErrorEquals": [
81+
"Lambda.ServiceException",
82+
"Lambda.AWSLambdaException",
83+
"Lambda.SdkClientException"
84+
],
85+
"IntervalSeconds": 2,
86+
"MaxAttempts": 6,
87+
"BackoffRate": 2
88+
}
89+
],
5690
"Next": "SetFareStatusCompleted",
57-
"Catch": [{
58-
"ErrorEquals": ["AccountCreditException"],
59-
"Next": "RefundFare",
60-
"ResultPath": "$.creditError"
61-
}]
91+
"Catch": [
92+
{
93+
"ErrorEquals": [
94+
"AccountCreditException"
95+
],
96+
"Next": "RefundFare",
97+
"ResultPath": "$.creditError"
98+
}
99+
]
62100
},
63101
"SetFareStatusCompleted": {
64102
"Type": "Task",
@@ -147,9 +185,25 @@
147185
"Type": "Succeed"
148186
},
149187
"RefundFare": {
150-
"Comment": "Add comment...",
151188
"Type": "Task",
152-
"Resource": "${PaymentRefundFunctionArn}",
189+
"Resource": "arn:aws:states:::lambda:invoke",
190+
"OutputPath": "$.Payload",
191+
"Parameters": {
192+
"Payload.$": "$",
193+
"FunctionName": "${PaymentRefundFunctionArn}"
194+
},
195+
"Retry": [
196+
{
197+
"ErrorEquals": [
198+
"Lambda.ServiceException",
199+
"Lambda.AWSLambdaException",
200+
"Lambda.SdkClientException"
201+
],
202+
"IntervalSeconds": 2,
203+
"MaxAttempts": 6,
204+
"BackoffRate": 2
205+
}
206+
],
153207
"Next": "SetFareStatusFailed"
154208
},
155209
"NotifyFailure": {

‎code/lab-4/template.drawio

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<mxfile host="" modified="2020年05月24日T15:21:41.060Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Code/1.45.0 Chrome/78.0.3904.130 Electron/7.2.4 Safari/537.36" version="13.1.3" etag="lrwgP8mNOWNbAz78NI_h" pages="2">
2+
<diagram id="diagramid" name="Diagram">
3+
<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="8" value="WildRydesFareProcessingTopic" style="outlineConnect=0;fontColor=#B3B3B3;gradientColor=#F34482;gradientDirection=north;fillColor=#BC1356;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.sns;" vertex="1" parent="1"><mxGeometry x="250" y="100" width="50" height="50" as="geometry"/></mxCell><mxCell id="9" value="WildRydesFailedTransactionsQueue" style="outlineConnect=0;fontColor=#B3B3B3;gradientColor=#F34482;gradientDirection=north;fillColor=#BC1356;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.sqs;" vertex="1" parent="1"><mxGeometry x="250" width="50" height="50" as="geometry"/></mxCell><mxCell id="10" value="WildRydesSuccessfulTransactionsQueue" style="outlineConnect=0;fontColor=#B3B3B3;gradientColor=#F34482;gradientDirection=north;fillColor=#BC1356;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.sqs;" vertex="1" parent="1"><mxGeometry x="250" y="200" width="50" height="50" as="geometry"/></mxCell><mxCell id="12" value="WildRydesFaresFailedSubscription" style="outlineConnect=0;fontColor=#B3B3B3;gradientColor=#F34482;gradientDirection=north;fillColor=#BC1356;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.sns;" vertex="1" parent="1"><mxGeometry y="50" width="50" height="50" as="geometry"/></mxCell><mxCell id="13" value="WildRydesFaresSuccessfulSubscription" style="outlineConnect=0;fontColor=#B3B3B3;gradientColor=#F34482;gradientDirection=north;fillColor=#BC1356;strokeColor=#ffffff;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=center;html=1;fontSize=12;fontStyle=0;aspect=fixed;shape=mxgraph.aws4.resourceIcon;resIcon=mxgraph.aws4.sns;" vertex="1" parent="1"><mxGeometry y="150" width="50" height="50" as="geometry"/></mxCell><mxCell id="WildRydesFareProcessingTopic|WildRydesFaresFailedSubscription" value="TopicArn" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;fontColor=#EA6B66;noEdgeStyle=1;orthogonal=1;" edge="1" parent="1" source="12" target="8"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="62" y="85"/><mxPoint x="238" y="115"/></Array></mxGeometry></mxCell><mxCell id="WildRydesFailedTransactionsQueue|WildRydesFaresFailedSubscription" value="Endpoint" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;fontColor=#EA6B66;noEdgeStyle=1;orthogonal=1;" edge="1" parent="1" source="12" target="9"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="62" y="65"/><mxPoint x="238" y="25"/></Array></mxGeometry></mxCell><mxCell id="WildRydesFareProcessingTopic|WildRydesFaresSuccessfulSubscription" value="TopicArn" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;fontColor=#EA6B66;noEdgeStyle=1;orthogonal=1;" edge="1" parent="1" source="13" target="8"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="62" y="165"/><mxPoint x="238" y="135"/></Array></mxGeometry></mxCell><mxCell id="WildRydesSuccessfulTransactionsQueue|WildRydesFaresSuccessfulSubscription" value="Endpoint" style="edgeStyle=orthogonalEdgeStyle;rounded=1;orthogonalLoop=1;jettySize=auto;html=1;labelBackgroundColor=none;fontColor=#EA6B66;noEdgeStyle=1;orthogonal=1;" edge="1" parent="1" source="13" target="10"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="62" y="185"/><mxPoint x="238" y="225"/></Array></mxGeometry></mxCell></root></mxGraphModel>
4+
</diagram>
5+
</mxfile>

‎code/lab-4/template.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Description: >
77
Globals:
88
Function:
99
Timeout: 3
10-
Runtime: python3.7
10+
Runtime: python3.9
1111
MemorySize: 512
1212
Tags:
1313
project: wild-rydes
@@ -57,6 +57,18 @@ Resources:
5757
End: true
5858
Policies:
5959
- CloudWatchPutMetricPolicy: {}
60+
- LambdaInvokePolicy:
61+
FunctionName: !Ref PaymentChargeFunction
62+
- LambdaInvokePolicy:
63+
FunctionName: !Ref PaymentRefundFunction
64+
- LambdaInvokePolicy:
65+
FunctionName: !Ref AccountCreditFunction
66+
- DynamoDBWritePolicy:
67+
TableName: !Ref FaresTable
68+
- DynamoDBReadPolicy:
69+
TableName: !Ref FaresTable
70+
- SNSPublishMessagePolicy:
71+
TopicName: !GetAtt WildRydesFareProcessingTopic.TopicName
6072
Tags:
6173
project: wild-rydes
6274
workshop: asynchronous-messaging-workshop
@@ -74,6 +86,7 @@ Resources:
7486
FareProcessingTable: !Ref FaresTable
7587
FareProcessingTopicArn: !Ref WildRydesFareProcessingTopic
7688
Policies:
89+
- CloudWatchPutMetricPolicy: {}
7790
- LambdaInvokePolicy:
7891
FunctionName: !Ref PaymentChargeFunction
7992
- LambdaInvokePolicy:

‎workshop/content/orchestration-and-coordination/_index.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@ pre = "Lab-4: "
88
Make sure you executed the **[Workshop Prerequisites](/prerequisites.html)** first, before you start with this lab!
99
{{% /notice %}}
1010

11-
AWS Step Functions is a fully managed Serverless workflow management service for managing long running processes and coordinating the components of distributed applications and microservices using visual workflows. But did you know it can also help you deal with the complexities of dealing with a long lived transaction across distributed components in your microservices architecture? In this Builder session, you will learn how AWS Step Function can help us implement the Saga design pattern.
11+
AWS Step Functions is a fully managed Serverless workflow management service for managing long running processes and coordinating the components of distributed applications and microservices using visual workflows. But did you know it can also help you deal with the complexities of dealing with a long lived transaction across distributed components in your microservices architecture?
12+
13+
In this Builder session, you will learn how AWS Step Functions can help us to implement the Saga design pattern.
1214

1315
## What problems are we trying to solve
1416

1517
When building cloud-based distributed architectures, one of the questions we need to ask ourselves is how do we maintain data consistency across microservices that have their own database / persistence mechanism? We do not have support for Distributed Transaction Coordinators (DTC) or two-phase commit protocols responsible for coordinating transactions across multiple cloud resources. We need a mechanism coordinate multiple local transactions.
1618

17-
## What is the Saga Pattern
19+
## The Saga Pattern
1820

1921
A Saga is a design pattern for dealing with "long-lived transactions" (LLT), published by Garcia-Molina and Salem in 1987. Their original paper can be found here [https://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf](https://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf).
2022

2123
> "LLT is a saga if it can be written as a sequence of transactions that can be interleaved with other transactions." (Garcia-Molina, Salem 1987)
2224
23-
Fundamentally it is a failure management pattern, that provides us the means to establish semantic consistency in our distributed applications by providing compensating transactions for every transaction where you have more than one collaborating services or functions.
25+
Fundamentally the Saga Pattern is a failure management pattern that provides a mechansim for providing semantic consistency in our distributed applications by providing compensating transactions for every transaction where you have more than one collaborating services or functions. This compensating transactions ensures the system remains in a consistent state by rolling back or compensating for partially completed transactions.
2426

2527
## Why AWS Step Functions
2628

@@ -30,7 +32,7 @@ AWS Step Functions provide us with a mechanism for dealing with long-lived trans
3032
* allowing us to build our state machines using visual workflows
3133
* provides us with a way to manage state and deal with failure
3234

33-
## Lab Objective
35+
## Lab Objectives
3436

3537
The core objective for this lab is to **build a state machine** that implements a Saga for the Wild Rydes Fare Collection process.
3638

@@ -42,6 +44,12 @@ The process consists of three discrete transactions that need to be treated as a
4244
1. **Payment Service**: calls a payment gateway for credit card pre-authorisation, and using the pre-authorisation code, completes the payment transaction
4345
1. **Customer Accounting Service**: once the payment has been processed, update the Wild Rydes Customer accounting system with the transaction details.
4446

47+
In this lab, you will acquire the following skills:
48+
49+
+ **How to create a Step Functions State Machine**
50+
+ **How to use the Step Functions Workflow Studio**
51+
+ **How to catch exceptions and manage retries in a Step Functions State Machine**
52+
+ **How to manage successful and non-successful execution flows in a Step Functions State machine**
4553

4654

4755
Let's get started!

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /