This repository has been archived by the owner on Aug 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
template.yaml
166 lines (154 loc) · 5.26 KB
/
template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
byd-delta-events
Template for byd-delta-events
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 10
Resources:
#Function Gets ByD Delta
GetBydObjectsFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: get-byd-objects/
Handler: app.lambdaHandler
Runtime: nodejs12.x
Policies:
# Give Create/Read/Update/Delete Permissions to the UserSessionTable
- DynamoDBCrudPolicy:
TableName: !Ref EventConfigTable
- SNSPublishMessagePolicy:
TopicName: "*"
Environment:
Variables:
#CHANGE to real system details
#ByD Details
BYD_ODATA: "https://my000000.sapbydesign.com/sap/byd/odata/cust/v1"
BYD_AUTH: "user:password base64 encoded"
BYD_INVOICES: "/khcustomerinvoice/CustomerInvoiceCollection"
BYD_INVOICES_ID: "ID"
BYD_CUSTOMERS: "/khcustomer/CustomerCollection"
BYD_CUSTOMERS_ID: "InternalID"
BYD_SALESORDERS: "/khsalesorder/SalesOrderCollection"
BYD_SALESORDERS_ID: "ID"
BYD_SERVICESORDERS: "/tmserviceorder/ServiceOrderCollection"
BYD_SERVICEORDERS_ID: "ID"
#AWS Details
CONFIG_TABLE: !Ref EventConfigTable
CONFIG_ID: 0
SNS_TOPIC: !Ref BydEventTopic
#Function Tweet an Event
TweetByDEvent:
Type: AWS::Serverless::Function
Properties:
CodeUri: tweet-byd-event/
Handler: app.lambdaHandler
Runtime: nodejs12.x
Environment:
Variables:
#TWITTER KEYS - Get yours on https://developer.twitter.com/apps
TWITER_API_KEY: "API KEY"
TWITTER_SECRET_KEY: "API SECRET"
TWITTER_ACCESS_TOKEN: "ACCESS TOKEN"
TWITTER_TOKEN_SECRET: "TOKEN SECRET"
#Function Send event to SCP
PublishEventSCP:
Type: AWS::Serverless::Function
Properties:
CodeUri: publish-event-scp/
Handler: app.lambdaHandler
Runtime: nodejs12.x
Environment:
Variables:
#SCP Authentication Details
SCP_EM_URL: "https://<SUB ACCOUNT>.authentication.eu10.hana.ondemand.com"
SCP_EM_AUTH_ENDPOINT: "/oauth/token"
#Enconde client_id:client_secret of SCP Enterprise Messaging
SCP_EM_AUTHORIZATION: "IT WILL BE A VERY LONG STRING"
SCP_EM_PUB_URL: "https://enterprise-messaging-pubsub.cfapps.eu10.hana.ondemand.com"
SCP_EM_PUB_ENDPOINT: "ENDPOINT FOR SCP PUBSUB"
#Function Toggle Vacuum ON/OFF
ToggleVacuumCleaner:
Type: AWS::Serverless::Function
Properties:
CodeUri: toggle-vacuum-cleaner/
Handler: app.lambdaHandler
Runtime: nodejs12.x
Environment:
Variables:
#SCP Authentication Details
WEBHOOK_BASE: "https://maker.ifttt.com"
WEBHOOK_ENDPOINT: "/trigger/ServiceOrder/with/key/<YOUR_KEY>"
#SNS Topic to handle Lambda Calls
BydEventTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: 'byd-event-topic'
TopicName: 'byd-event'
Subscription:
- Protocol: lambda
Endpoint: !GetAtt TweetByDEvent.Arn
- Protocol: lambda
Endpoint: !GetAtt PublishEventSCP.Arn
- Protocol: lambda
Endpoint: !GetAtt ToggleVacuumCleaner.Arn
TweetByDEventInvokePermission:
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:InvokeFunction'
FunctionName: !Ref TweetByDEvent
Principal: sns.amazonaws.com
PublishEventSCPInvokePermission:
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:InvokeFunction'
FunctionName: !Ref PublishEventSCP
Principal: sns.amazonaws.com
ToggleVacuumCleanerInvokePermission:
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:InvokeFunction'
FunctionName: !Ref ToggleVacuumCleaner
Principal: sns.amazonaws.com
# DynamoDB table to store item: {id: <ID>, name: <NAME>}
EventConfigTable:
Type: AWS::Serverless::SimpleTable
Properties:
TableName: EventConfigTable
PrimaryKey:
Name: configId
Type: Number
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
#Cloud Watch Event to Trigger function on timer
ScheduledRule:
Type: AWS::Events::Rule
Properties:
Description: "Invoke Byd Delta function"
Name: "trigger-byd-delta"
State: "ENABLED"
ScheduleExpression: "rate(1 minute)"
Targets:
-
Arn:
Fn::GetAtt:
- "GetBydObjectsFunction"
- "Arn"
Id: "TargetFunctionV1"
PermissionForEventsToInvokeLambda:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref GetBydObjectsFunction
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt "ScheduledRule.Arn"
Outputs:
GetBydObjectsFunction:
Description: "Get ByD Objects Function ARN"
Value: !GetAtt GetBydObjectsFunction.Arn
GetBydObjectsFunctionIamRole:
Description: "Get ByD Objects Function"
Value: !GetAtt GetBydObjectsFunctionRole.Arn