@geek-fun/serverlessinsight 0.4.0 → 0.5.0

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 (160) hide show
  1. package/.gitattributes +1 -0
  2. package/README.md +108 -8
  3. package/README.zh-CN.md +52 -8
  4. package/dist/package.json +37 -35
  5. package/dist/src/commands/deploy.js +17 -7
  6. package/dist/src/commands/destroy.js +27 -4
  7. package/dist/src/commands/forceUnlock.js +61 -0
  8. package/dist/src/commands/index.js +86 -14
  9. package/dist/src/commands/local.js +10 -1
  10. package/dist/src/commands/plan.js +33 -0
  11. package/dist/src/commands/template.js +3 -1
  12. package/dist/src/commands/validate.js +2 -1
  13. package/dist/src/common/aliyunClient/apigwOperations.js +652 -0
  14. package/dist/src/common/aliyunClient/dnsOperations.js +90 -0
  15. package/dist/src/common/aliyunClient/ecsOperations.js +141 -0
  16. package/dist/src/common/aliyunClient/esOperations.js +219 -0
  17. package/dist/src/common/aliyunClient/fc3Operations.js +270 -0
  18. package/dist/src/common/aliyunClient/index.js +141 -0
  19. package/dist/src/common/aliyunClient/nasOperations.js +233 -0
  20. package/dist/src/common/aliyunClient/ossOperations.js +237 -0
  21. package/dist/src/common/aliyunClient/ramOperations.js +205 -0
  22. package/dist/src/common/aliyunClient/rdsOperations.js +206 -0
  23. package/dist/src/common/aliyunClient/slsOperations.js +218 -0
  24. package/dist/src/common/aliyunClient/tablestoreOperations.js +199 -0
  25. package/dist/src/common/aliyunClient/types.js +2 -0
  26. package/dist/src/common/constants.js +7 -1
  27. package/dist/src/common/context.js +32 -14
  28. package/dist/src/common/credentials.js +39 -0
  29. package/dist/src/common/dependencyGraph/graph.js +280 -0
  30. package/dist/src/common/dependencyGraph/index.js +18 -0
  31. package/dist/src/common/dependencyGraph/types.js +2 -0
  32. package/dist/src/common/fileUtils.js +16 -0
  33. package/dist/src/common/hashUtils.js +121 -0
  34. package/dist/src/common/iacHelper.js +25 -97
  35. package/dist/src/common/imsClient.js +4 -0
  36. package/dist/src/common/index.js +7 -2
  37. package/dist/src/common/lockManager.js +212 -0
  38. package/dist/src/common/logger.js +89 -6
  39. package/dist/src/common/providerEnum.js +2 -3
  40. package/dist/src/common/runtimeMapper.js +160 -0
  41. package/dist/src/common/scfClient.js +84 -0
  42. package/dist/src/common/stateManager.js +107 -0
  43. package/dist/src/common/tencentClient/cosOperations.js +287 -0
  44. package/dist/src/common/tencentClient/esOperations.js +156 -0
  45. package/dist/src/common/tencentClient/index.js +116 -0
  46. package/dist/src/common/tencentClient/scfOperations.js +141 -0
  47. package/dist/src/common/tencentClient/tdsqlcOperations.js +211 -0
  48. package/dist/src/common/tencentClient/types.js +17 -0
  49. package/dist/src/lang/en.js +254 -0
  50. package/dist/src/lang/index.js +28 -8
  51. package/dist/src/lang/zh-CN.js +229 -0
  52. package/dist/src/parser/bucketParser.js +25 -12
  53. package/dist/src/parser/databaseParser.js +14 -10
  54. package/dist/src/parser/functionParser.js +19 -6
  55. package/dist/src/parser/parseUtils.js +74 -0
  56. package/dist/src/parser/tableParser.js +19 -17
  57. package/dist/src/stack/aliyunStack/apigwExecutor.js +84 -0
  58. package/dist/src/stack/aliyunStack/apigwPlanner.js +118 -0
  59. package/dist/src/stack/aliyunStack/apigwResource.js +339 -0
  60. package/dist/src/stack/aliyunStack/apigwTypes.js +125 -0
  61. package/dist/src/stack/aliyunStack/databaseExecutor.js +112 -0
  62. package/dist/src/stack/aliyunStack/databasePlanner.js +128 -0
  63. package/dist/src/stack/aliyunStack/databaseResource.js +228 -0
  64. package/dist/src/stack/aliyunStack/deployer.js +133 -0
  65. package/dist/src/stack/aliyunStack/destroyer.js +114 -0
  66. package/dist/src/stack/aliyunStack/esServerlessTypes.js +141 -0
  67. package/dist/src/stack/aliyunStack/fc3Executor.js +91 -0
  68. package/dist/src/stack/aliyunStack/fc3Planner.js +77 -0
  69. package/dist/src/stack/aliyunStack/fc3Resource.js +511 -0
  70. package/dist/src/stack/aliyunStack/fc3Types.js +76 -0
  71. package/dist/src/stack/aliyunStack/index.js +40 -0
  72. package/dist/src/stack/aliyunStack/ossExecutor.js +91 -0
  73. package/dist/src/stack/aliyunStack/ossPlanner.js +76 -0
  74. package/dist/src/stack/aliyunStack/ossResource.js +196 -0
  75. package/dist/src/stack/aliyunStack/ossTypes.js +50 -0
  76. package/dist/src/stack/aliyunStack/planner.js +37 -0
  77. package/dist/src/stack/aliyunStack/rdsTypes.js +217 -0
  78. package/dist/src/stack/aliyunStack/tablestoreExecutor.js +92 -0
  79. package/dist/src/stack/aliyunStack/tablestorePlanner.js +94 -0
  80. package/dist/src/stack/aliyunStack/tablestoreResource.js +120 -0
  81. package/dist/src/stack/aliyunStack/tablestoreTypes.js +77 -0
  82. package/dist/src/stack/bucketTypes.js +17 -0
  83. package/dist/src/stack/deploy.js +24 -77
  84. package/dist/src/stack/localStack/bucket.js +11 -6
  85. package/dist/src/stack/localStack/event.js +10 -5
  86. package/dist/src/stack/localStack/function.js +13 -7
  87. package/dist/src/stack/localStack/functionRunner.js +1 -1
  88. package/dist/src/stack/localStack/localServer.js +7 -6
  89. package/dist/src/stack/scfStack/cosExecutor.js +91 -0
  90. package/dist/src/stack/scfStack/cosPlanner.js +76 -0
  91. package/dist/src/stack/scfStack/cosResource.js +126 -0
  92. package/dist/src/stack/scfStack/cosTypes.js +46 -0
  93. package/dist/src/stack/scfStack/deployer.js +91 -0
  94. package/dist/src/stack/scfStack/destroyer.js +88 -0
  95. package/dist/src/stack/scfStack/esServerlessExecutor.js +105 -0
  96. package/dist/src/stack/scfStack/esServerlessPlanner.js +86 -0
  97. package/dist/src/stack/scfStack/esServerlessResource.js +94 -0
  98. package/dist/src/stack/scfStack/esServerlessTypes.js +48 -0
  99. package/dist/src/stack/scfStack/index.js +35 -0
  100. package/dist/src/stack/scfStack/planner.js +91 -0
  101. package/dist/src/stack/scfStack/scfExecutor.js +91 -0
  102. package/dist/src/stack/scfStack/scfPlanner.js +78 -0
  103. package/dist/src/stack/scfStack/scfResource.js +216 -0
  104. package/dist/src/stack/scfStack/scfTypes.js +41 -0
  105. package/dist/src/stack/scfStack/tdsqlcExecutor.js +105 -0
  106. package/dist/src/stack/scfStack/tdsqlcPlanner.js +90 -0
  107. package/dist/src/stack/scfStack/tdsqlcResource.js +146 -0
  108. package/dist/src/stack/scfStack/tdsqlcTypes.js +59 -0
  109. package/dist/src/types/domains/lock.js +2 -0
  110. package/dist/src/types/domains/resolvable.js +2 -0
  111. package/dist/src/types/domains/state.js +19 -0
  112. package/dist/src/types/index.js +4 -0
  113. package/dist/src/validator/bucketSchema.js +4 -10
  114. package/dist/src/validator/databaseSchema.js +36 -36
  115. package/dist/src/validator/eventSchema.js +3 -2
  116. package/dist/src/validator/functionSchema.js +51 -46
  117. package/dist/src/validator/iacSchema.js +52 -3
  118. package/dist/src/validator/rootSchema.js +47 -1
  119. package/dist/src/validator/tableschema.js +9 -8
  120. package/dist/src/validator/templateRefSchema.js +23 -0
  121. package/dist/tsconfig.tsbuildinfo +1 -1
  122. package/package.json +37 -35
  123. package/samples/README_TENCENT_COS.md +486 -0
  124. package/samples/README_TENCENT_SCF.md +272 -0
  125. package/samples/aliyun-poc-api.yml +1 -1
  126. package/samples/aliyun-poc-bucket.yml +0 -1
  127. package/samples/aliyun-poc-domain.yml +0 -1
  128. package/samples/aliyun-poc-es.yml +14 -13
  129. package/samples/aliyun-poc-rds.yml +0 -2
  130. package/samples/aliyun-poc-table.yml +1 -3
  131. package/samples/tencent-poc-cos.yml +20 -0
  132. package/samples/tencent-poc-scf.yml +36 -0
  133. package/dist/src/commands/index.d.ts +0 -2
  134. package/dist/src/common/index.d.ts +0 -11
  135. package/dist/src/common/rosAssets.js +0 -178
  136. package/dist/src/common/rosClient.js +0 -198
  137. package/dist/src/index.d.ts +0 -1
  138. package/dist/src/lang/index.d.ts +0 -3
  139. package/dist/src/parser/index.d.ts +0 -3
  140. package/dist/src/stack/index.d.ts +0 -1
  141. package/dist/src/stack/localStack/index.d.ts +0 -5
  142. package/dist/src/stack/rfsStack/index.d.ts +0 -9
  143. package/dist/src/stack/rosStack/bootstrap.js +0 -187
  144. package/dist/src/stack/rosStack/bucket.js +0 -127
  145. package/dist/src/stack/rosStack/database.js +0 -313
  146. package/dist/src/stack/rosStack/event.js +0 -143
  147. package/dist/src/stack/rosStack/function.js +0 -259
  148. package/dist/src/stack/rosStack/index.d.ts +0 -7
  149. package/dist/src/stack/rosStack/index.js +0 -75
  150. package/dist/src/stack/rosStack/stage.js +0 -46
  151. package/dist/src/stack/rosStack/table.js +0 -95
  152. package/dist/src/stack/rosStack/tag.js +0 -11
  153. package/dist/src/stack/rosStack/vars.js +0 -49
  154. package/dist/src/types/index.d.ts +0 -55
  155. package/dist/src/types/localStack/index.d.ts +0 -81
  156. package/dist/src/validator/index.d.ts +0 -1
  157. package/layers/si-bootstrap-sdk/Dockerfile-aliyuncli +0 -12
  158. package/layers/si-bootstrap-sdk/README.md +0 -1
  159. package/layers/si-bootstrap-sdk/package-lock.json +0 -875
  160. package/layers/si-bootstrap-sdk/package.json +0 -33
@@ -1,198 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.rosStackDelete = exports.rosStackDeploy = void 0;
40
- const ros20190910_1 = __importStar(require("@alicloud/ros20190910"));
41
- const openapi_client_1 = require("@alicloud/openapi-client");
42
- const tea_util_1 = __importDefault(require("@alicloud/tea-util"));
43
- const logger_1 = require("./logger");
44
- const lang_1 = require("../lang");
45
- const context_1 = require("./context");
46
- const client = new ros20190910_1.default(new openapi_client_1.Config({
47
- accessKeyId: process.env.ALIYUN_ACCESS_KEY_ID,
48
- accessKeySecret: process.env.ALIYUN_ACCESS_KEY_SECRET,
49
- regionId: process.env.ALIYUN_REGION,
50
- disableRollback: false,
51
- }));
52
- const createStack = async (stackName, templateBody, context) => {
53
- const parameters = context.parameters?.map((parameter) => new ros20190910_1.CreateStackRequestParameters({
54
- parameterKey: tea_util_1.default.assertAsString(parameter.key),
55
- parameterValue: tea_util_1.default.assertAsString(parameter.value),
56
- }));
57
- const createStackRequest = new ros20190910_1.CreateStackRequest({
58
- regionId: context.region,
59
- sync: true,
60
- stackName,
61
- templateBody: JSON.stringify(templateBody),
62
- parameters,
63
- tags: context.tags?.map((tag) => new ros20190910_1.CreateStackRequestTags(tag)),
64
- });
65
- const response = await client.createStack(createStackRequest);
66
- logger_1.logger.info(`创建中,资源栈ID:${response.body?.stackId}`);
67
- // wait for stack create complete
68
- return await getStackActionResult(response.body?.stackId || '', context.region);
69
- };
70
- const updateStack = async (stackId, templateBody, context) => {
71
- const parameters = context.parameters?.map((parameter) => new ros20190910_1.UpdateStackRequestParameters({
72
- parameterKey: tea_util_1.default.assertAsString(parameter.key),
73
- parameterValue: tea_util_1.default.assertAsString(parameter.key),
74
- }));
75
- const updateStackRequest = new ros20190910_1.UpdateStackRequest({
76
- regionId: context.region,
77
- stackId,
78
- templateBody: JSON.stringify(templateBody),
79
- parameters,
80
- tags: context.tags?.map((tag) => new ros20190910_1.CreateStackRequestTags(tag)),
81
- });
82
- try {
83
- const response = await client.updateStack(updateStackRequest);
84
- logger_1.logger.info(`更新中,资源栈ID: ${response.body?.stackId}`);
85
- // wait for stack update complete
86
- return await getStackActionResult(response.body?.stackId || '', context.region);
87
- }
88
- catch (err) {
89
- const { message, statusCode } = err || {};
90
- if (statusCode === 400 && message.includes('Update the completely same stack')) {
91
- logger_1.logger.warn(`${lang_1.lang.__('UPDATE_COMPLETELY_SAME_STACK')}`);
92
- return null;
93
- }
94
- else {
95
- throw err;
96
- }
97
- }
98
- };
99
- const getStackByName = async (stackName, region) => {
100
- const result = await client.listStacks(new ros20190910_1.ListStacksRequest({
101
- regionId: region,
102
- pageSize: 10,
103
- pageNumber: 1,
104
- stackName: [stackName],
105
- }));
106
- if (result.statusCode === 200) {
107
- return result.body?.stacks?.[0];
108
- }
109
- else {
110
- return null;
111
- }
112
- };
113
- const getStackActionResult = async (stackId, region) => {
114
- return new Promise((resolve, reject) => {
115
- const startTime = Date.now();
116
- const interval = setInterval(async () => {
117
- try {
118
- const result = await client.getStack(new ros20190910_1.GetStackRequest({ regionId: region, stackId }));
119
- const status = result.body?.status ?? '';
120
- logger_1.logger.info(`stack status: ${status}`);
121
- if ([
122
- 'CREATE_COMPLETE',
123
- 'UPDATE_COMPLETE',
124
- 'DELETE_COMPLETE',
125
- 'CHECK_COMPLETE',
126
- 'IMPORT_CREATE_COMPLETE',
127
- 'IMPORT_UPDATE_COMPLETE',
128
- ].includes(status)) {
129
- clearInterval(interval);
130
- resolve(result.body);
131
- }
132
- else if ([
133
- 'CREATE_ROLLBACK_FAILED',
134
- 'CREATE_ROLLBACK_COMPLETE',
135
- 'ROLLBACK_FAILED',
136
- 'ROLLBACK_COMPLETE',
137
- 'IMPORT_CREATE_ROLLBACK_FAILED',
138
- 'IMPORT_CREATE_ROLLBACK_COMPLETE',
139
- 'IMPORT_UPDATE_ROLLBACK_FAILED',
140
- 'IMPORT_UPDATE_ROLLBACK_COMPLETE',
141
- ].includes(status)) {
142
- clearInterval(interval);
143
- reject(new Error(`Stack operation failed with status: ${status}`));
144
- }
145
- else if (Date.now() - startTime > 3600000) {
146
- // 1 hour in milliseconds
147
- clearInterval(interval);
148
- reject(new Error('Stack operation did not finish within 1 hour'));
149
- }
150
- }
151
- catch (error) {
152
- clearInterval(interval);
153
- reject(error);
154
- }
155
- }, 5000); // 5 seconds interval
156
- });
157
- };
158
- const rosStackDeploy = async (stackName, templateBody) => {
159
- const context = (0, context_1.getContext)();
160
- const stackInfo = await getStackByName(stackName, context.region);
161
- if (stackInfo) {
162
- const { Status: stackStatus } = stackInfo;
163
- if (stackStatus?.indexOf('IN_PROGRESS') >= 0) {
164
- throw new Error(`fail to update stack, because stack status is ${stackStatus}`);
165
- }
166
- logger_1.logger.info(`Update stack: ${stackName} deploying... `);
167
- const stack = await updateStack(stackInfo.stackId, templateBody, context);
168
- logger_1.logger.info(`stackUpdate success! stackName:${stack?.stackName}, stackId:${stack?.stackId}`);
169
- }
170
- else {
171
- // create stack
172
- logger_1.logger.info(`Create stack: ${stackName} deploying... `);
173
- const stack = await createStack(stackName, templateBody, context);
174
- logger_1.logger.info(`createStack success! stackName:${stack?.stackName}, stackId:${stack?.stackId}`);
175
- }
176
- };
177
- exports.rosStackDeploy = rosStackDeploy;
178
- const rosStackDelete = async ({ stackName, region, }) => {
179
- const stackInfo = await getStackByName(stackName, region);
180
- if (!stackInfo) {
181
- logger_1.logger.warn(`Stack: ${stackName} not exists, skipped! 🚫`);
182
- return;
183
- }
184
- try {
185
- const deleteStackRequest = new ros20190910_1.DeleteStackRequest({
186
- regionId: region,
187
- stackId: stackInfo.stackId,
188
- });
189
- await client.deleteStack(deleteStackRequest);
190
- await getStackActionResult(stackInfo.stackId, region);
191
- logger_1.logger.info(`Stack: ${stackName} deleted!🗑 `);
192
- }
193
- catch (err) {
194
- logger_1.logger.error(`Stack: ${stackName} delete failed! ❌, error: ${JSON.stringify(err)}`);
195
- throw new Error(JSON.stringify(err));
196
- }
197
- };
198
- exports.rosStackDelete = rosStackDelete;
@@ -1 +0,0 @@
1
- export declare const hello: () => string;
@@ -1,3 +0,0 @@
1
- import { I18n } from 'i18n';
2
- declare const lang: I18n;
3
- export { lang };
@@ -1,3 +0,0 @@
1
- import { ServerlessIac, Context } from '../types';
2
- export declare const parseYaml: (iacLocation: string) => ServerlessIac;
3
- export declare const revalYaml: (iacLocation: string, ctx: Context) => ServerlessIac;
@@ -1 +0,0 @@
1
- export { deployStack } from './deploy';
@@ -1,5 +0,0 @@
1
- import { stopLocal } from './localServer';
2
- import { ServerlessIac } from '../../types';
3
- export * from './event';
4
- export { stopLocal };
5
- export declare const startLocalStack: (iac: ServerlessIac) => Promise<void>;
@@ -1,9 +0,0 @@
1
- import { Context, ServerlessIac } from '../../types';
2
- export declare class RfsStack {
3
- private readonly iac;
4
- private readonly context;
5
- private hcl;
6
- constructor(iac: ServerlessIac, context?: Context);
7
- toHclTerraform(): string;
8
- appendHcl(hcl: string): void;
9
- }
@@ -1,187 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prepareBootstrapStack = void 0;
4
- const common_1 = require("../../common");
5
- const getBootstrapTemplate = async (context) => {
6
- const stackName = `si-bootstrap-${context.accountId}-${context.region}`;
7
- const template = {
8
- Description: 'ServerlessInsight Bootstrap Stack',
9
- Metadata: {
10
- 'ALIYUN::ROS::Interface': {
11
- TemplateTags: ['Bootstrap stack created by ServerlessInsight'],
12
- },
13
- },
14
- ROSTemplateFormatVersion: '2015-09-01',
15
- Resources: {
16
- si_auto_artifacts_bucket: {
17
- Type: 'ALIYUN::OSS::Bucket',
18
- Properties: {
19
- BucketName: `${common_1.SI_BOOTSTRAP_BUCKET_PREFIX}-${context.accountId}-${context.region}`,
20
- AccessControl: 'private',
21
- DeletionForce: false,
22
- EnableOssHdfsService: false,
23
- RedundancyType: 'LRS',
24
- ServerSideEncryptionConfiguration: {
25
- SSEAlgorithm: 'KMS',
26
- },
27
- },
28
- },
29
- si_auto_bootstrap_api_lambda: {
30
- Type: 'ALIYUN::FC3::Function',
31
- Properties: {
32
- FunctionName: `${common_1.SI_BOOTSTRAP_FC_PREFIX}-${context.accountId}-${context.region}`,
33
- Description: 'ServerlessInsight Bootstrap API',
34
- Handler: 'index.handler',
35
- Runtime: 'nodejs20',
36
- Layers: [`acs:fc:${context.region}:1990893136649406:layers/si-bootstrap-sdk/versions/18`],
37
- Code: {
38
- SourceCode: `
39
- const { bootstrapHandler } = require('@geek-fun/si-bootstrap-sdk');
40
-
41
- module.exports.handler = async (rawEvent, context) => {
42
- // 处理 Buffer 类型的事件
43
- const event = parseEvent(rawEvent);
44
-
45
- const commonResponse = {
46
- RequestId: event.requestId,
47
- LogicalResourceId: event.logicalResourceId,
48
- StackId: event.stackId
49
- };
50
-
51
- try {
52
- // 处理业务逻辑
53
- const result = await bootstrapHandler(event);
54
-
55
- // 构建符合 ROS 要求的响应结构
56
- const rosResponse = {
57
- ...commonResponse,
58
- Status: result.status,
59
- Reason: result.reason,
60
- PhysicalResourceId: result.physicalResourceId,
61
- Data: result.data || {} // 业务数据
62
- };
63
-
64
- // 如果是删除操作,不需要返回数据
65
- if (event.requestType === 'Delete') {
66
- delete rosResponse.Data;
67
- }
68
-
69
- // 发送响应到 ROS 服务(如果提供了 ResponseURL)
70
- if (event.responseURL) {
71
- await sendResponse(event.responseURL, rosResponse);
72
- }
73
-
74
- // 返回成功响应
75
- return {
76
- statusCode: 200,
77
- body: JSON.stringify({
78
- message: 'Request processed successfully',
79
- rosResponse
80
- })
81
- };
82
- } catch (error) {
83
- console.error('Error:', error);
84
-
85
- // 构建错误响应
86
- const errorResponse = {
87
- ...commonResponse,
88
- Status: 'FAILED',
89
- Reason: error.message || 'Internal Server Error',
90
- PhysicalResourceId: 'error-' + Date.now()
91
- };
92
-
93
- // 发送错误响应到 ROS 服务
94
- if (event.responseURL) {
95
- try {
96
- await sendResponse(event.responseURL, errorResponse);
97
- } catch (err) {
98
- console.error('Failed to send error response:', err);
99
- }
100
- }
101
-
102
- // 返回错误响应
103
- return {
104
- statusCode: 500,
105
- body: JSON.stringify({
106
- error: 'Internal Server Error',
107
- details: error.message,
108
- rosErrorResponse: errorResponse
109
- })
110
- };
111
- }
112
- };
113
-
114
- // 使用原生 fetch API 发送响应
115
- async function sendResponse(responseUrl, responseBody) {
116
-
117
- try {
118
- const body = JSON.stringify(responseBody);
119
-
120
- const response = await fetch(responseUrl, {
121
- method: 'POST',
122
- headers: {
123
- 'Content-Type': 'application/json',
124
- 'Content-Length': Buffer.byteLength(body).toString(),
125
- 'Date': new Date().toUTCString()
126
- },
127
- body: body
128
- });
129
-
130
- if (!response.ok) {
131
- const errorText = await response.text();
132
- throw new Error(\`Failed to send response. Status: \${response.status}, Body: \${errorText}\`);
133
- }
134
-
135
- console.log('Response sent successfully');
136
- } catch (error) {
137
- console.error('Error sending response:', error);
138
- throw error;
139
- }
140
- }
141
-
142
-
143
- const parseEvent = (rawEvent) => {
144
- // 处理 Buffer 类型的事件
145
- let event;
146
- if (Buffer.isBuffer(rawEvent)) {
147
- event = JSON.parse(rawEvent.toString('utf8'));
148
- } else if (typeof rawEvent === 'string') {
149
- event = JSON.parse(rawEvent);
150
- } else {
151
- event = rawEvent;
152
- }
153
-
154
- const { credentials, ...resourceProperties } = event.ResourceProperties
155
- return {
156
- stackId: event.StackId,
157
- responseURL: event.ResponseURL,
158
- resourceOwnerId: event.ResourceOwnerId,
159
- callerId: event.CallerId,
160
- resourceProperties,
161
- eventType: event.ResourceType,
162
- requestType: event.RequestType?.toUpperCase(),
163
- resourceType: resourceProperties.resource,
164
- regionId: event.RegionId,
165
- stackName: event.StackName,
166
- requestId: event.RequestId,
167
- intranetResponseURL: event.IntranetResponseURL,
168
- logicalResourceId: event.LogicalResourceId,
169
- physicalResourceId: event.PhysicalResourceId,
170
- credentials
171
- };
172
- };`,
173
- },
174
- MemorySize: 512,
175
- Timeout: 900, // 15 minutes
176
- },
177
- },
178
- },
179
- };
180
- return { stackName, template };
181
- };
182
- const prepareBootstrapStack = async () => {
183
- const context = (0, common_1.getContext)();
184
- const { stackName, template } = await getBootstrapTemplate(context);
185
- await (0, common_1.rosStackDeploy)(stackName, template);
186
- };
187
- exports.prepareBootstrapStack = prepareBootstrapStack;
@@ -1,127 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.resolveBuckets = void 0;
40
- const types_1 = require("../../types");
41
- const oss = __importStar(require("@alicloud/ros-cdk-oss"));
42
- const ros = __importStar(require("@alicloud/ros-cdk-core"));
43
- const common_1 = require("../../common");
44
- const ossDeployment = __importStar(require("@alicloud/ros-cdk-ossdeployment"));
45
- const dns = __importStar(require("@alicloud/ros-cdk-dns"));
46
- const node_path_1 = __importDefault(require("node:path"));
47
- const ros_cdk_ram_1 = require("@alicloud/ros-cdk-ram");
48
- const aclMap = new Map([
49
- [types_1.BucketAccessEnum.PRIVATE, 'private'],
50
- [types_1.BucketAccessEnum.PUBLIC_READ, 'public-read'],
51
- [types_1.BucketAccessEnum.PUBLIC_READ_WRITE, 'public-read-write'],
52
- ]);
53
- const resolveBuckets = (scope, buckets, context) => {
54
- if (!buckets) {
55
- return undefined;
56
- }
57
- const bucketSources = buckets.some((bucket) => bucket?.website?.code);
58
- let siAutoOssDeploymentBucketRole;
59
- if (bucketSources) {
60
- siAutoOssDeploymentBucketRole = new ros_cdk_ram_1.RosRole(scope, 'si_auto_od_bucket_role', {
61
- roleName: ros.Fn.sub('si-auto-od-bucket-role-${ALIYUN::StackId}'),
62
- description: 'roles created by ServerlessInsight for oss deployment to put files to oss bucket during deployment',
63
- deletionForce: false,
64
- ignoreExisting: false,
65
- assumeRolePolicyDocument: {
66
- version: '1',
67
- statement: [
68
- {
69
- action: 'sts:AssumeRole',
70
- effect: 'Allow',
71
- principal: { service: ['fc.aliyuncs.com'] },
72
- },
73
- ],
74
- },
75
- policyAttachments: {
76
- system: ['AliyunOSSFullAccess', 'AliyunLogFullAccess'],
77
- },
78
- }, true);
79
- }
80
- buckets.forEach((bucket) => {
81
- const ossBucket = new oss.Bucket(scope, bucket.key, {
82
- bucketName: (0, common_1.calcRefs)(bucket.name, context),
83
- accessControl: aclMap.get((0, common_1.calcRefs)(bucket.security?.acl, context) ?? ''),
84
- blockPublicAccess: (0, common_1.calcRefs)(bucket.security?.acl, context) === types_1.BucketAccessEnum.PRIVATE,
85
- websiteConfigurationV2: bucket.website
86
- ? {
87
- indexDocument: {
88
- type: '0',
89
- suffix: (0, common_1.calcRefs)(bucket.website.index, context),
90
- supportSubDir: 'true',
91
- },
92
- errorDocument: {
93
- httpStatus: `${(0, common_1.calcRefs)(bucket.website.error_code, context)}`,
94
- key: (0, common_1.calcRefs)(bucket.website.error_page, context),
95
- },
96
- }
97
- : undefined,
98
- });
99
- if (bucket.website?.code) {
100
- const filePath = node_path_1.default.resolve(process.cwd(), (0, common_1.calcValue)(bucket.website.code, context));
101
- new ossDeployment.BucketDeployment(scope, (0, common_1.formatRosId)(`si_auto_${bucket.key}_bucket_code_deployment`), {
102
- sources: (0, common_1.getAssets)(filePath),
103
- destinationBucket: ossBucket.attrName,
104
- roleArn: siAutoOssDeploymentBucketRole.attrArn,
105
- timeout: common_1.OSS_DEPLOYMENT_TIMEOUT,
106
- logMonitoring: false,
107
- retainOnCreate: false,
108
- }, true);
109
- }
110
- if (bucket.website?.domain) {
111
- const { rr, domainName } = (0, common_1.splitDomain)(bucket.website.domain);
112
- new oss.Domain(scope, (0, common_1.formatRosId)(`${bucket.key}_custom_domain`), {
113
- bucketName: ossBucket.attrName,
114
- domainName: (0, common_1.calcRefs)(bucket.website.domain, context),
115
- });
116
- new dns.DomainRecord(scope, (0, common_1.formatRosId)(`${bucket.key}_custom_domain_record`), {
117
- domainName: domainName,
118
- rr,
119
- type: 'CNAME',
120
- value: [types_1.BucketAccessEnum.PUBLIC_READ, types_1.BucketAccessEnum.PUBLIC_READ_WRITE].includes(bucket.security?.acl ?? '')
121
- ? ossBucket.attrDomainName
122
- : ossBucket.attrInternalDomainName,
123
- });
124
- }
125
- });
126
- };
127
- exports.resolveBuckets = resolveBuckets;