Skip to content

Commit 8da0e35

Browse files
author
Ben Smith
authored
Merge pull request #12 from ironspur5/main
Refactored to Use SDK Service Integrations
2 parents 1927c6a + 6603f27 commit 8da0e35

File tree

8 files changed

+148
-267
lines changed

8 files changed

+148
-267
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Read more about Synchronous Express Workflows in this [AWS blog post](https://aw
99

1010
This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders:
1111

12-
- functions - Code for the application's Lambda functions.
12+
- functions - Code for the application's Lambda function.
1313
- statemachines - Definition for the state machine that orchestrates AWS services.
1414
- template.yaml - A template that defines the application's AWS resources.
1515
- api.yaml - A template that defines the application's HTTP API resource.
@@ -35,7 +35,7 @@ The Serverless Application Model Command Line Interface (SAM CLI) is an extensio
3535
To use the SAM CLI, you need the following tools:
3636

3737
* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
38-
* Node.js - [Install Node.js 12](https://nodejs.org/en/), including the NPM package management tool.
38+
* Node.js - [Install Node.js 16](https://nodejs.org/en/), including the NPM package management tool.
3939
* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community)
4040

4141
To build and deploy your application for the first time, run the following in your shell:

functions/detectSentiment/index.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

functions/detectSentiment/package.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

functions/sendEmailConfirmation/index.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

functions/sendEmailConfirmation/package.json

Lines changed: 0 additions & 15 deletions
This file was deleted.
-384 KB
Loading

statemachine/sfn-template.asl.json

Lines changed: 111 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,112 @@
11
{
2-
"Comment": "A serverless form processor with a number of useful reference components",
3-
"StartAt": "Detect Sentiment ",
4-
"States": {
5-
"Detect Sentiment ": {
6-
"Type": "Task",
7-
"Resource": "arn:aws:states:::lambda:invoke",
8-
"Parameters": {
9-
"FunctionName": "${DetectSentiment}",
10-
"Payload.$": "$"
11-
},
12-
"Retry": [
13-
{
14-
"ErrorEquals": [
15-
"Lambda.ServiceException",
16-
"Lambda.AWSLambdaException",
17-
"Lambda.SdkClientException"
18-
],
19-
"IntervalSeconds": 2,
20-
"MaxAttempts": 6,
21-
"BackoffRate": 2
22-
}
23-
],
24-
"Next": "Generate Customer Reference Number",
25-
"ResultPath": "$.SentimentResults"
26-
},
27-
"Generate Customer Reference Number": {
28-
"Type": "Task",
29-
"Resource": "arn:aws:states:::lambda:invoke",
30-
"Parameters": {
31-
"FunctionName": "${GenerateRefernceNumber}"
32-
},
33-
"Retry": [
34-
{
35-
"ErrorEquals": [
36-
"Lambda.ServiceException",
37-
"Lambda.AWSLambdaException",
38-
"Lambda.SdkClientException"
39-
],
40-
"IntervalSeconds": 2,
41-
"MaxAttempts": 6,
42-
"BackoffRate": 2
43-
}
44-
],
45-
"Next": "Record Transaction",
46-
"ResultPath": "$.ticketId"
47-
},
48-
"Record Transaction": {
49-
"Type": "Task",
50-
"Resource": "arn:aws:states:::dynamodb:putItem",
51-
"Parameters": {
52-
"TableName": "${DDBTable}",
53-
"Item": {
54-
"formId": {
55-
"S.$": "$.ticketId.Payload"
56-
},
57-
"formData": {
58-
"S.$": "States.JsonToString($.message)"
59-
},
60-
"sentiment": {
61-
"S.$": "States.JsonToString($.SentimentResults.Payload.Sentiment)"
62-
}
63-
}
64-
},
65-
"Retry": [
66-
{
67-
"ErrorEquals": [
68-
"States.TaskFailed"
69-
],
70-
"IntervalSeconds": 20,
71-
"MaxAttempts": 5,
72-
"BackoffRate": 10
73-
}
74-
],
75-
"ResultPath": "$.ddbPutResult",
76-
"Next": "Good Or Bad?"
77-
},
78-
"Good Or Bad?": {
79-
"Type": "Choice",
80-
"Choices": [
81-
{
82-
"Variable": "$.SentimentResults.Payload.Sentiment",
83-
"StringEquals": "NEGATIVE",
84-
"Next": "Bad"
85-
},
86-
{
87-
"Variable": "$.SentimentResults.Payload.Sentiment",
88-
"StringEquals": "POSITIVE",
89-
"Next": "Not Bad"
90-
}
91-
],
92-
"Default": "Not Bad"
93-
},
94-
"Not Bad": {
95-
"Type": "Succeed",
96-
"Comment": "not a negative message"
97-
},
98-
"Bad": {
99-
"Type": "Pass",
100-
"Comment": "Negative sentiment",
101-
"Next": "Notify Admin By Email"
102-
},
103-
"Notify Admin By Email": {
104-
"Type": "Task",
105-
"Resource": "arn:aws:states:::lambda:invoke",
106-
"Parameters": {
107-
"Payload.$": "$",
108-
"FunctionName": "${NotifyAdminWithSES}"
109-
},
110-
"Retry": [
111-
{
112-
"ErrorEquals": [
113-
"Lambda.ServiceException",
114-
"Lambda.AWSLambdaException",
115-
"Lambda.SdkClientException"
116-
],
117-
"IntervalSeconds": 2,
118-
"MaxAttempts": 6,
119-
"BackoffRate": 2
120-
}
121-
],
122-
"ResultPath": "$.SESOutput",
123-
"End": true
124-
}
125-
}
126-
}
2+
"Comment": "A serverless form processor with a number of useful reference components",
3+
"StartAt": "Detect Sentiment",
4+
"States": {
5+
"Detect Sentiment": {
6+
"Type": "Task",
7+
"Resource": "arn:aws:states:::aws-sdk:comprehend:detectSentiment",
8+
"Parameters": {
9+
"LanguageCode": "en",
10+
"Text.$": "$.message"
11+
},
12+
"Next": "Generate Customer Reference Number",
13+
"ResultPath": "$.SentimentResults"
14+
},
15+
"Generate Customer Reference Number": {
16+
"Type": "Task",
17+
"Resource": "arn:aws:states:::lambda:invoke",
18+
"Parameters": {
19+
"FunctionName": "${GenerateRefernceNumber}"
20+
},
21+
"Retry": [{
22+
"ErrorEquals": [
23+
"Lambda.ServiceException",
24+
"Lambda.AWSLambdaException",
25+
"Lambda.SdkClientException"
26+
],
27+
"IntervalSeconds": 2,
28+
"MaxAttempts": 6,
29+
"BackoffRate": 2
30+
}],
31+
"Next": "Record Transaction",
32+
"ResultPath": "$.ticketId"
33+
},
34+
"Record Transaction": {
35+
"Type": "Task",
36+
"Resource": "arn:aws:states:::dynamodb:putItem",
37+
"Parameters": {
38+
"TableName": "${DDBTable}",
39+
"Item": {
40+
"formId": {
41+
"S.$": "$.ticketId.Payload"
42+
},
43+
"formData": {
44+
"S.$": "States.JsonToString($.message)"
45+
},
46+
"sentiment": {
47+
"S.$": "States.JsonToString($.SentimentResults.Sentiment)"
48+
}
49+
}
50+
},
51+
"Retry": [{
52+
"ErrorEquals": [
53+
"States.TaskFailed"
54+
],
55+
"IntervalSeconds": 20,
56+
"MaxAttempts": 5,
57+
"BackoffRate": 10
58+
}],
59+
"ResultPath": "$.ddbPutResult",
60+
"Next": "Good Or Bad?"
61+
},
62+
"Good Or Bad?": {
63+
"Type": "Choice",
64+
"Choices": [{
65+
"Variable": "$.SentimentResults.Sentiment",
66+
"StringEquals": "NEGATIVE",
67+
"Next": "Bad"
68+
},
69+
{
70+
"Variable": "$.SentimentResults.Sentiment",
71+
"StringEquals": "POSITIVE",
72+
"Next": "Not Bad"
73+
}
74+
],
75+
"Default": "Not Bad"
76+
},
77+
"Not Bad": {
78+
"Type": "Succeed",
79+
"Comment": "Not a negative message"
80+
},
81+
"Bad": {
82+
"Type": "Pass",
83+
"Comment": "Negative sentiment",
84+
"Next": "Notify Admin By Email"
85+
},
86+
"Notify Admin By Email": {
87+
"Type": "Task",
88+
"Resource": "arn:aws:states:::aws-sdk:ses:sendEmail",
89+
"Parameters": {
90+
"Message": {
91+
"Body": {
92+
"Text": {
93+
"Data.$": "States.JsonToString($.message)"
94+
}
95+
},
96+
"Subject": {
97+
"Data": "New Form Submission"
98+
}
99+
},
100+
"Source": "${ValidatedEmail}",
101+
"ReplyToAddresses": ["${ValidatedEmail}"],
102+
"Destination": {
103+
"ToAddresses": [
104+
"${ValidatedEmail}"
105+
]
106+
}
107+
},
108+
"ResultPath": "$.SESOutput",
109+
"End": true
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)