@izara_project/izara-market-library-service-schemas 1.0.16 → 1.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/package.json +4 -4
  2. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +24 -0
  3. package/src/TemplateManager/src/FindData/FindDataYaml/data.js +0 -9
  4. package/src/TemplateManager/src/GenerateCode.js +26 -17
  5. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/mainFunction/template.ejs +1 -1
  6. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/template.ejs +2 -2
  7. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/template.ejs +2 -2
  8. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/template.ejs +41 -29
  9. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Update/template.ejs +73 -1
  10. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationshipComplete/mainFunction/template.ejs +1 -1
  11. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/mainFunction/template.ejs +1 -1
  12. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationshipComplete/mainFunction/template.ejs +1 -1
  13. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/template.ejs +1 -1
  14. package/src/TemplateManager/src/ResourceYaml/dynamodb/defaultDynamoDbTable.js +15 -0
  15. package/src/TemplateManager/src/externalService/LambdaRole/data.js +7 -20
  16. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +1 -1
  17. package/src/TemplateManager/src/flowTag/webSocket/webSocketComplete/functionYaml/data.js +100 -0
  18. package/src/TemplateManager/src/flowTag/webSocket/webSocketComplete/functionYaml/template.ejs +27 -0
  19. package/src/TemplateManager/src/flowTag/webSocket/webSocketComplete/handler/data.js +58 -0
  20. package/src/TemplateManager/src/flowTag/webSocket/webSocketComplete/handler/template.ejs +103 -0
  21. package/src/TemplateManager/src/flowTag/webSocket/webSocketComplete/mainFunction/data.js +56 -0
  22. package/src/TemplateManager/src/flowTag/webSocket/webSocketComplete/mainFunction/template.ejs +180 -0
  23. package/src/TemplateManager/src/flowTag/webSocket/webSocketComplete/sns-sqs/data.js +70 -0
  24. package/src/TemplateManager/src/flowTag/webSocket/webSocketComplete/sns-sqs/template.ejs +43 -0
  25. package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/functionYaml/data.js +22 -5
  26. package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/functionYaml/template.ejs +22 -3
  27. package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/handler/data.js +3 -3
  28. package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/handler/template.ejs +19 -14
  29. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/functionYaml/data.js +32 -8
  30. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/functionYaml/template.ejs +5 -7
  31. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/handler/data.js +59 -0
  32. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/handler/template.ejs +130 -0
  33. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/{lambda → mainFunction}/data.js +5 -3
  34. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/mainFunction/template.ejs +133 -0
  35. package/src/TemplateManager/src/libs/Consts.js +5 -2
  36. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/lambda/template.ejs +0 -131
@@ -0,0 +1,27 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionName) %><%- handlerType -%>:
3
+ handler: <%- join(resourceLocation, `${functionName}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- functionName %><%- firstLetterUpperCase(handlerType) %>
5
+ events:
6
+ - sqs:
7
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- functionName %><%- firstLetterUpperCase(handlerType) %>
8
+ batchSize: 10
9
+ iamRoleStatements:
10
+ <%_ additionalResourcePermission.forEach(resourcePermission => { _%>
11
+ - Effect: <%- resourcePermission.effect %>
12
+ Action:
13
+ <%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
14
+ <%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
15
+ - <%- resourcePerAction %>:<%- permission %>
16
+ <%_ }) _%>
17
+ <%_ }) _%>
18
+ Resource:
19
+ <%_ resourcePermission.resource.forEach(resource => { _%>
20
+ - "<%- resource %>"
21
+ <%_ }) _%>
22
+ <%_}) _%>
23
+ #<#<%- functionName %><%- handlerType %>IamRole#>
24
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
25
+ <%_ function firstLetterUpperCase(text){
26
+ return text.charAt(0).toUpperCase() + text.slice(1)
27
+ } _%>
@@ -0,0 +1,58 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require('path');
21
+
22
+ const templatePath = path.join(__dirname, "./template.ejs")
23
+
24
+ const { HANDLER, STORAGE_TYPES, ACTIONS } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
25
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils")
26
+ const { createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SQS_RESOURCE, SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME, shortNameHandler, defaultIamRolePerAction, DYNAMO_RESOURCE } = require("../../../../libs/Consts");
27
+
28
+
29
+ /**
30
+ * receive objectSchema
31
+ * create data for FindData Yaml template
32
+ *
33
+ * @param {Object} objectSchemas
34
+ * @return {{ templatePath, templateData, setting } }
35
+ */
36
+ function data(_izContext, srcPath) {
37
+ return [createSourceParams(_izContext, srcPath)]
38
+ }
39
+
40
+ function createSourceParams(_izContext, srcPath) {
41
+ let functionName = "WebSocketTaskComplete"
42
+ let handlerType = upperCase(HANDLER.hdrSqs)
43
+ return {
44
+ templatePath: templatePath,
45
+ templateData: {
46
+ functionName,
47
+ handlerType,
48
+ },
49
+ setting: {
50
+ savePath: path.join(srcPath, SOURCE_PATH.webSocket),
51
+ saveFileName: `${functionName}_${handlerType}`,
52
+ fileExtension: ".js",
53
+ isAppend: false
54
+ }
55
+ }
56
+ }
57
+
58
+ module.exports = data;
@@ -0,0 +1,103 @@
1
+ /*
2
+ Copyright (C) 2021 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ // const AWS = require('aws-sdk');
21
+ // const sqs = new AWS.SQS({ apiVersion: '2012-11-05' });
22
+ const izara = require('@izara_project/izara-middleware');
23
+ const middleware = izara.middlewareHandler;;
24
+ const Logger = require('@izara_project/izara-core-library-logger');
25
+ const izaraShared = require("@izara_project/izara-shared");
26
+ const recordHandlerSharedLib = izaraShared.recordHandlerSharedLib
27
+
28
+ const webSocketTaskComplete = require('./WebSocketTaskComplete_Main')
29
+
30
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
31
+ // set schema for record.body.Message
32
+ const perRecordsValidatorSchema = {};
33
+
34
+ // // set schema for record.body.MessageAttributes
35
+ // const messageAttributeValidatorSchema = {
36
+ // type: "object",
37
+ // required: ['msgAtrrParam1', 'msgAtrrParam2'],
38
+ // properties: {
39
+ // msgAtrrParam1: {
40
+ // type: "string"
41
+ // },
42
+ // msgAtrrParam2: {
43
+ // type: "object"
44
+ // }
45
+ // }
46
+ // };
47
+
48
+
49
+ // middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema(perRecordsValidatorSchema));
50
+
51
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
52
+
53
+ try {
54
+ Logger.debug('event ReceiveMsgOutHdrSqs: ', event)
55
+ let recordPromises = [];
56
+
57
+ // loop each record and send to mainFunction
58
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
59
+
60
+ let passOnProperties = []
61
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
62
+
63
+ //validate message (and MessageAttributes)
64
+ await recordHandlerSharedLib.validateRecord(
65
+ record, // one record will send to mainFunction
66
+ "WebSocketTaskCompleteHdrSqs", // queue name that need to retry or send to dlq
67
+ perRecordsValidatorSchema, // schema for record.Message
68
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
69
+ );
70
+
71
+ // add argument (to invoke lambda) to passOnProperties[]
72
+ // passOnProperties.push(record.body.Message.MessageAttributes)
73
+ passOnProperties.push(record.body.Message)
74
+ // passOnProperties.push(record.body.Message.route)
75
+ passOnProperties.push(record.body.TopicArn)
76
+ Logger.debug('passOnProperties in handler', passOnProperties);
77
+
78
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
79
+ let recordPromise = recordHandlerSharedLib.recordHandler(
80
+ record, // one record will send to mainFunction
81
+ webSocketTaskComplete.webSocketTaskComplete, // mainFunction that need to invoke.
82
+ "WebSocketTaskCompleteHdrSqs", // queue name that need to retry or send to dlq
83
+ passOnProperties, // all parameters that mainFunction needed.
84
+ );
85
+ record._izContext.logger.debug('after recordPromise in handler');
86
+ recordPromises.push(recordPromise); // push promise to recordPromises
87
+ }))
88
+ // ProcessLogical
89
+ Logger.debug('before Promise.all(recordPromises) in handler');
90
+ try {
91
+ await Promise.all(recordPromises); // await all promises
92
+ return event.Records // return all for local test
93
+
94
+ } catch {
95
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did not resolve)');
96
+ }
97
+ Logger.debug('after Promise.all(recordPromises) in handler');
98
+
99
+ } catch (err) {
100
+ Logger.error('Unhandled Error, WebSocketTaskCompleteHdrSqs: ', err);
101
+ throw (err);
102
+ }
103
+ });
@@ -0,0 +1,56 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require('path');
21
+
22
+ const templatePath = path.join(__dirname, "./template.ejs")
23
+
24
+ const { HANDLER, STORAGE_TYPES, ACTIONS } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
25
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils")
26
+ const { createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SQS_RESOURCE, SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME, shortNameHandler, defaultIamRolePerAction, DYNAMO_RESOURCE } = require("../../../../libs/Consts");
27
+
28
+
29
+ /**
30
+ * receive objectSchema
31
+ * create data for FindData Yaml template
32
+ *
33
+ * @param {Object} objectSchemas
34
+ * @return {{ templatePath, templateData, setting } }
35
+ */
36
+ function data(_izContext, srcPath) {
37
+ return [createSourceParams(_izContext, srcPath)]
38
+ }
39
+
40
+ function createSourceParams(_izContext, srcPath) {
41
+ let functionName = "WebSocketTaskComplete"
42
+ return {
43
+ templatePath: templatePath,
44
+ templateData: {
45
+ functionName,
46
+ },
47
+ setting: {
48
+ savePath: path.join(srcPath, SOURCE_PATH.webSocket),
49
+ saveFileName: `${functionName}_Main`,
50
+ fileExtension: ".js",
51
+ isAppend: false
52
+ }
53
+ }
54
+ }
55
+
56
+ module.exports = data;
@@ -0,0 +1,180 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ 'use strict';
18
+ const { NoRetryError } = require('@izara_project/izara-core-library-core');
19
+ const izaraShared = require('@izara_project/izara-shared');
20
+ const dynamodbSharedLib = izaraShared.dynamodbSharedLib;
21
+ const snsSharedLib = izaraShared.snsSharedLib;
22
+ const asyncFlowSharedLib = izaraShared.asyncFlowSharedLib;
23
+ const AWS = require('aws-sdk');
24
+ const api = new AWS.ApiGatewayManagementApi({
25
+ endpoint: process.env.iz_webSocketEndpoint,
26
+ });
27
+
28
+ module.exports.webSocketTaskComplete = async (
29
+ _izContext,
30
+ passStatus,
31
+ errorsFound,
32
+ uploadUrl,
33
+ imageImportId,
34
+ maximumSize,
35
+ cacheStatus,
36
+ imageImportCacheData,
37
+ imageImportCacheId,
38
+ // route,
39
+ topicArn
40
+ ) => {
41
+ // _izContext.logger.debug('functionGet params: ', params);
42
+ try {
43
+
44
+ // you must have data in table.
45
+ console.log("topicArn", topicArn)
46
+ let taskId = imageImportId;
47
+ let taskTag = null;
48
+
49
+ switch (topicArn) {
50
+ case snsSharedLib.snsTopicArn("OutReservedImageLimitComplete"):
51
+ taskTag = 'UploadImage';
52
+ break
53
+ // case 'message':
54
+ // break
55
+ // default:
56
+ // console.log('Received unknown route:', route)
57
+ }
58
+
59
+ // console.log("topicArn", topicArn)
60
+ // let taskTag = topicArn.split(":")[5];
61
+ // let taskId = sortResultId;
62
+ // console.log("taskTag", taskTag)
63
+ // switch (taskTag) {
64
+ // case 'SortedResultsTestSortResultComplete':
65
+ // taskTag = 'SortedResultsTestSortResultComplete';
66
+ // break
67
+ // // case 'message':
68
+ // // break
69
+ // // default:
70
+ // // console.log('Received unknown route:', route)
71
+ // }
72
+
73
+ let webSocketTask = null;
74
+
75
+ for (let i = 0; i < 4; i++) {
76
+ // let value = await dynamodbSharedLib.getItem(
77
+ webSocketTask = await dynamodbSharedLib.query(
78
+ _izContext,
79
+ dynamodbSharedLib.tableName("WebSocketTask"),
80
+ {
81
+ taskKey: taskTag + "_" + taskId,
82
+ // connectionid: "ZKPBId2CCYcCG6A="
83
+ }
84
+ );
85
+
86
+ if (webSocketTask.length < 1) {
87
+ continue;
88
+ } else {
89
+ break;
90
+ }
91
+ }
92
+ console.log("Item: ", webSocketTask.Items)
93
+
94
+ for (let itemIter = 0; itemIter < webSocketTask.Items.length; itemIter++) {
95
+
96
+ let connectionid = webSocketTask.Items[itemIter].connectionid;
97
+ let taskKey = webSocketTask.Items[itemIter].taskKey;
98
+
99
+ // if (route) {
100
+ let data = {};
101
+
102
+ if (cacheStatus) {
103
+ data = {
104
+ connId: connectionid,
105
+ cacheStatus: cacheStatus,
106
+ imageImportId: imageImportId,
107
+ imageImportCacheId: imageImportCacheId,
108
+ imageImportCacheData: imageImportCacheData
109
+ }
110
+ }
111
+
112
+ if (passStatus) {
113
+ if (passStatus === 'complete') {
114
+ let maxSize = maximumSize / 1048576
115
+ data = {
116
+ connId: connectionid,
117
+ passStatus: passStatus,
118
+ imageImportId: imageImportId,
119
+ uploadUrl: uploadUrl,
120
+ maximumSize: `${maxSize} MiB`
121
+ }
122
+ } else if (passStatus === 'error') {
123
+ data = {
124
+ connId: connectionid,
125
+ passStatus: passStatus,
126
+ imageImportId: imageImportId,
127
+ errorsFound: errorsFound
128
+ }
129
+ } else {
130
+ throw new NoRetryError('Another passStatus: pass status is not complete or error')
131
+ }
132
+ }
133
+
134
+ try {
135
+ _izContext.logger.debug("endpoint: ", process.env.iz_webSocketEndpoint)
136
+ await postMessage(
137
+ data,
138
+ connectionid
139
+ )
140
+ } catch (err) {
141
+ _izContext.logger.info("postMessage error: ", err, connectionid);
142
+ }
143
+ // }
144
+
145
+
146
+ await dynamodbSharedLib.deleteItem(
147
+ _izContext,
148
+ dynamodbSharedLib.tableName("WebSocketTask"),
149
+ {
150
+ taskKey: taskKey,
151
+ connectionid: connectionid,
152
+ }
153
+ );
154
+ console.log('testdelete and delete item')
155
+
156
+ _izContext.logger.debug("connectionid", connectionid, itemIter)
157
+ }
158
+
159
+ async function postMessage(data, connectionId) {
160
+ const params = {
161
+ ConnectionId: connectionId,
162
+ Data: JSON.stringify(data),
163
+ // Data: Buffer.from(JSON.stringify(data)),
164
+ }
165
+ return api.postToConnection(params).promise();
166
+ };
167
+
168
+ //loop value and send message back to client
169
+ //fix cachetime
170
+ const time = new Date();
171
+ _izContext.logger.debug("value:", webSocketTask, Date.now(), new Date(), time, time.toLocaleTimeString())
172
+ return {
173
+ value: webSocketTask
174
+ }
175
+
176
+ } catch (err) {
177
+ _izContext.logger.error('error websocketTaskComplete: ', err)
178
+ throw (err);
179
+ }
180
+ };
@@ -0,0 +1,70 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require("path")
21
+
22
+ const {
23
+ HANDLER,
24
+ STORAGE_TYPES
25
+ } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
26
+
27
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../../MainLibs/src/Utils")
28
+ const templatePath = path.join(__dirname, "template.ejs")
29
+ const { SOURCE_PATH, SAVE_FILE_NAME, FUNCTION_NAME } = require('../../../../libs/Consts')
30
+
31
+
32
+ /**
33
+ * create data for dynamoDbYaml tempalte from objectSchema
34
+ * return array of dynamoDb data
35
+ * because one objectSchema can create multiple dynamoDb table
36
+ *
37
+ * @param {Object} _izContext
38
+ * @param {String} saveFilePath
39
+ * @returns {Object[]} - data of multiple dynamoDb template
40
+ */
41
+
42
+ function createDataForDefaultSnsInSqs(_izContext, srcPath) {
43
+ let resultsForCreateDefaultSnsInSqs = [];
44
+ const defaultSnsInSqsDataList = [];
45
+ const setting = {
46
+ initialData: "Resources:\n",
47
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
48
+ saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
49
+ fileExtension: ".yml",
50
+ isAppend: true
51
+ }
52
+
53
+
54
+ defaultSnsInSqsDataList.push(
55
+ {
56
+ queueName: upperCase("webSocketTaskComplete" + upperCase(HANDLER.hdrSqs))
57
+ }
58
+ )
59
+
60
+ for (let defaultSnsInSqsData of defaultSnsInSqsDataList) {
61
+ resultsForCreateDefaultSnsInSqs.push({
62
+ templatePath: templatePath,
63
+ templateData: defaultSnsInSqsData,
64
+ setting: setting
65
+ })
66
+ }
67
+ return resultsForCreateDefaultSnsInSqs;
68
+ }
69
+
70
+ module.exports = createDataForDefaultSnsInSqs;
@@ -0,0 +1,43 @@
1
+ #------- queue ---------
2
+ <%- queueName %>:
3
+ Type: "AWS::SQS::Queue"
4
+ Properties:
5
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
6
+ RedrivePolicy:
7
+ deadLetterTargetArn: #!GetAtt
8
+ Fn::GetAtt:
9
+ - <%- queueName %>DLQ
10
+ - Arn
11
+ maxReceiveCount: 3
12
+ VisibilityTimeout: 120
13
+
14
+ <%- queueName %>DLQ:
15
+ Type: AWS::SQS::Queue
16
+ Properties:
17
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
18
+
19
+ <%- queueName %>Policy:
20
+ Type: AWS::SQS::QueuePolicy
21
+ Properties:
22
+ PolicyDocument:
23
+ Version: "2012-10-17"
24
+ Statement:
25
+ - Sid: "allow-sns-messages"
26
+ Effect: Allow
27
+ Principal: "*"
28
+ Resource: #!GetAtt
29
+ Fn::GetAtt:
30
+ - <%- queueName %>
31
+ - Arn
32
+ Action: "SQS:SendMessage"
33
+ Queues:
34
+ - Ref: <%- queueName %>
35
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
36
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
37
+
38
+ <%_ function firstLetterUpperCase(text){
39
+ return text.charAt(0).toUpperCase() + text.slice(1)
40
+ } _%>
41
+ <%_ function firstLetterLowerCase(str) {
42
+ return str.charAt(0).toLowerCase() + str.slice(1)
43
+ } _%>
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  const path = require('path');
20
20
  const fs = require('fs');
21
21
 
22
- const { SOURCE_PATH, SAVE_FILE_NAME, ACTIONS, HANDLER } = require("../../../../libs/Consts");
22
+ const { SOURCE_PATH, SAVE_FILE_NAME, ACTIONS, HANDLER, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, DYNAMO_RESOURCE, resourceNames } = require("../../../../libs/Consts");
23
23
 
24
24
  const templatePath = path.join(__dirname, "./template.ejs")
25
25
 
@@ -32,22 +32,39 @@ const templatePath = path.join(__dirname, "./template.ejs")
32
32
  */
33
33
 
34
34
  function data(_izContext, srcPath) {
35
- let createSourceParam;
36
- createSourceParam = [createWebSocketConnectYaml(_izContext, srcPath)]
35
+ let createSourceParam = [createWebSocketConnectYaml(_izContext, srcPath)]
37
36
  return createSourceParam
38
37
  }
39
38
 
40
39
  function createWebSocketConnectYaml(_izContext, srcPath) {
41
40
  let functionName = "WebSocketConnect"
41
+ let additionalResourcePermission = defaultIamRolePerAction();
42
+
43
+
44
+ additionalResourcePermission.push(
45
+ createIamRole(
46
+ {
47
+ [RESOURCE_CLASSES.dynamoDbTable]: [
48
+ DYNAMO_RESOURCE.putItem,
49
+ DYNAMO_RESOURCE.deleteItem
50
+ ]
51
+ },
52
+ [
53
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, "WebSocketTask")
54
+ ]
55
+ )
56
+ )
57
+
42
58
  return {
43
59
  templatePath: templatePath,
44
60
  templateData: {
45
61
  functionName,
46
- resourceLocation: SOURCE_PATH.resourceLocationPerAction
62
+ resourceLocation: SOURCE_PATH.resourceLocationWebSocket,
63
+ additionalResourcePermission
47
64
  },
48
65
  setting: {
49
66
  savePath: path.join(srcPath, SOURCE_PATH.appYaml),
50
- saveFileName: "FlowSchemaInvoke",
67
+ saveFileName: SAVE_FILE_NAME.flowSchema,
51
68
  fileExtension: ".yml",
52
69
  isAppend: true
53
70
  }
@@ -1,10 +1,29 @@
1
- WebSocketConnect:
2
- handler: src/generatedCode/ObjectTypePerActionEndpoint/source/WebSocketConnect.main
3
- name: ${self:custom.iz_resourcePrefix}WebSocketConnect
1
+ <%_ const join = require('path').join %>
2
+ <%- firstLetterUpperCase(functionName) -%>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}.main`) %>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %>
4
5
  events:
5
6
  - websocket:
6
7
  route: $connect
7
8
  - websocket:
8
9
  route: $disconnect
10
+ iamRoleStatements:
11
+ <%_ additionalResourcePermission.forEach(resourcePermission => { _%>
12
+ - Effect: <%- resourcePermission.effect %>
13
+ Action:
14
+ <%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
15
+ <%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
16
+ - <%- resourcePerAction %>:<%- permission %>
17
+ <%_ }) _%>
18
+ <%_ }) _%>
19
+ Resource:
20
+ <%_ resourcePermission.resource.forEach(resource => { _%>
21
+ - "<%- resource %>"
22
+ <%_ }) _%>
23
+ <%_}) _%>
9
24
  #<#<WebSocketConnectIamRole#>
10
25
  #<#/<WebSocketConnectIamRole#>
26
+
27
+ <%_ function firstLetterUpperCase(text){
28
+ return text.charAt(0).toUpperCase() + text.slice(1)
29
+ } _%>
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
  const path = require('path');
20
20
  const fs = require('fs');
21
21
 
22
- const { SOURCE_PATH, SAVE_FILE_NAME, ACTIONS, HANDLER } = require("../../../../libs/Consts");
22
+ const { SOURCE_PATH, SAVE_FILE_NAME, ACTIONS, HANDLER, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, DYNAMO_RESOURCE, resourceNames } = require("../../../../libs/Consts");
23
23
 
24
24
  const templatePath = path.join(__dirname, "./template.ejs")
25
25
 
@@ -45,10 +45,10 @@ function createWebSocketConnectYaml(_izContext, srcPath) {
45
45
  functionName,
46
46
  },
47
47
  setting: {
48
- savePath: path.join(srcPath, SOURCE_PATH.lambdaPerAction),
48
+ savePath: path.join(srcPath, SOURCE_PATH.webSocket),
49
49
  saveFileName: functionName,
50
50
  fileExtension: ".js",
51
- isAppend: true
51
+ isAppend: false
52
52
  }
53
53
  }
54
54
  }