@goldstack/template-lambda-api 0.4.41 → 0.4.44

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 (59) hide show
  1. package/dist/src/templateLambdaApi.d.ts +0 -1
  2. package/dist/src/templateLambdaApi.d.ts.map +1 -1
  3. package/dist/src/templateLambdaApi.js +0 -71
  4. package/dist/src/templateLambdaApi.js.map +1 -1
  5. package/package.json +9 -28
  6. package/bin/template +0 -12
  7. package/bin/template.ts +0 -6
  8. package/dist/src/generateLambdaConfig.d.ts +0 -5
  9. package/dist/src/generateLambdaConfig.d.ts.map +0 -1
  10. package/dist/src/generateLambdaConfig.js +0 -28
  11. package/dist/src/generateLambdaConfig.js.map +0 -1
  12. package/dist/src/generateLambdaConfig.spec.d.ts +0 -2
  13. package/dist/src/generateLambdaConfig.spec.d.ts.map +0 -1
  14. package/dist/src/generateLambdaConfig.spec.js +0 -72
  15. package/dist/src/generateLambdaConfig.spec.js.map +0 -1
  16. package/dist/src/templateLambdaApiBuild.d.ts +0 -9
  17. package/dist/src/templateLambdaApiBuild.d.ts.map +0 -1
  18. package/dist/src/templateLambdaApiBuild.js +0 -50
  19. package/dist/src/templateLambdaApiBuild.js.map +0 -1
  20. package/dist/src/templateLambdaApiBuild.spec.d.ts +0 -2
  21. package/dist/src/templateLambdaApiBuild.spec.d.ts.map +0 -1
  22. package/dist/src/templateLambdaApiBuild.spec.js +0 -50
  23. package/dist/src/templateLambdaApiBuild.spec.js.map +0 -1
  24. package/dist/src/templateLambdaApiDeploy.d.ts +0 -10
  25. package/dist/src/templateLambdaApiDeploy.d.ts.map +0 -1
  26. package/dist/src/templateLambdaApiDeploy.js +0 -37
  27. package/dist/src/templateLambdaApiDeploy.js.map +0 -1
  28. package/dist/src/templateLambdaConsts.d.ts +0 -2
  29. package/dist/src/templateLambdaConsts.d.ts.map +0 -1
  30. package/dist/src/templateLambdaConsts.js +0 -5
  31. package/dist/src/templateLambdaConsts.js.map +0 -1
  32. package/dist/tsconfig.tsbuildinfo +0 -1
  33. package/jest.config.js +0 -12
  34. package/schemas/deployment-configuration.schema.json +0 -74
  35. package/schemas/deployment.schema.json +0 -176
  36. package/schemas/package-configuration.schema.json +0 -16
  37. package/schemas/package.schema.json +0 -244
  38. package/scripts/buildTestLambdas.ts +0 -23
  39. package/scripts/generateSchemas.ts +0 -3
  40. package/src/generateLambdaConfig.spec.ts +0 -97
  41. package/src/generateLambdaConfig.ts +0 -37
  42. package/src/templateLambdaApi.ts +0 -88
  43. package/src/templateLambdaApiBuild.spec.ts +0 -49
  44. package/src/templateLambdaApiBuild.ts +0 -72
  45. package/src/templateLambdaApiDeploy.ts +0 -54
  46. package/src/templateLambdaConsts.ts +0 -1
  47. package/src/types/LambdaApiPackage.ts +0 -90
  48. package/testData/build-test/customBuild.esbuild.config.json +0 -5
  49. package/testData/build-test/customBuild.ts +0 -10
  50. package/testData/build-test/index.ts +0 -12
  51. package/testData/routes-test/$default.ts +0 -0
  52. package/testData/routes-test/folder/nested.ts +0 -0
  53. package/testData/routes-test/folder/{pathparam}.ts +0 -0
  54. package/testData/routes-test/health/$index.ts +0 -0
  55. package/testData/routes-test/index.ts +0 -0
  56. package/testData/routes-test/resource/{path}/object.ts +0 -0
  57. package/testData/routes-test/resource.ts +0 -0
  58. package/tsconfig.generate.json +0 -12
  59. package/tsconfig.json +0 -64
@@ -1,244 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "$ref": "#/definitions/ThisPackage",
4
- "definitions": {
5
- "ThisPackage": {
6
- "type": "object",
7
- "properties": {
8
- "template": {
9
- "$ref": "#/definitions/Template"
10
- },
11
- "templateVersion": {
12
- "$ref": "#/definitions/TemplateVersion"
13
- },
14
- "name": {
15
- "$ref": "#/definitions/Name"
16
- },
17
- "configuration": {
18
- "$ref": "#/definitions/ThisPackageConfiguration"
19
- },
20
- "deployments": {
21
- "$ref": "#/definitions/LambdaApiDeployments"
22
- },
23
- "$schema": {
24
- "type": "string"
25
- }
26
- },
27
- "required": [
28
- "$schema",
29
- "configuration",
30
- "deployments",
31
- "name",
32
- "template",
33
- "templateVersion"
34
- ],
35
- "additionalProperties": false,
36
- "description": "A deployment for a lambda API.",
37
- "title": "Lambda API Package"
38
- },
39
- "Template": {
40
- "type": "string",
41
- "description": "Name of the template used for creating this package.",
42
- "title": "Template",
43
- "pattern": "^[^\\s]*$"
44
- },
45
- "TemplateVersion": {
46
- "type": "string",
47
- "description": "Latest template version that was applied to this package.",
48
- "title": "Template Version"
49
- },
50
- "Name": {
51
- "type": "string",
52
- "description": "Name of this package.",
53
- "title": "Package Name"
54
- },
55
- "ThisPackageConfiguration": {
56
- "$ref": "#/definitions/PackageConfiguration",
57
- "description": "Configures this lambda.",
58
- "title": "Lambda Configuration"
59
- },
60
- "PackageConfiguration": {
61
- "type": "object",
62
- "description": "Configuration of this package",
63
- "title": "Configuration"
64
- },
65
- "LambdaApiDeployments": {
66
- "type": "array",
67
- "items": {
68
- "$ref": "#/definitions/ThisDeployment"
69
- },
70
- "description": "Places where the lambda should be deployed to.",
71
- "title": "Deployments"
72
- },
73
- "ThisDeployment": {
74
- "type": "object",
75
- "properties": {
76
- "name": {
77
- "$ref": "#/definitions/DeploymentName"
78
- },
79
- "configuration": {
80
- "$ref": "#/definitions/ThisDeploymentConfiguration"
81
- },
82
- "terraformVariables": {
83
- "$ref": "#/definitions/TerraformVariables"
84
- },
85
- "tfStateKey": {
86
- "$ref": "#/definitions/TerraformStateKey"
87
- },
88
- "tfVersion": {
89
- "$ref": "#/definitions/TerraformVersion"
90
- },
91
- "awsRegion": {
92
- "$ref": "#/definitions/AWSDeploymentRegion"
93
- },
94
- "awsUser": {
95
- "$ref": "#/definitions/AWSUserName"
96
- }
97
- },
98
- "required": [
99
- "awsRegion",
100
- "awsUser",
101
- "configuration",
102
- "name"
103
- ]
104
- },
105
- "DeploymentName": {
106
- "type": "string",
107
- "description": "Identifier for this deployment. No spaces allowed in name.",
108
- "title": "Deployment Name",
109
- "pattern": "^[^\\s]*$"
110
- },
111
- "ThisDeploymentConfiguration": {
112
- "type": "object",
113
- "properties": {
114
- "lambdaNamePrefix": {
115
- "type": "string",
116
- "description": "The prefix to be used for names of the generated lambdas for the API endpoints.",
117
- "title": "Lambda Name Prefix",
118
- "pattern": "^[A-Za-z0-9-_]*$"
119
- },
120
- "apiDomain": {
121
- "$ref": "#/definitions/APIDomain"
122
- },
123
- "hostedZoneDomain": {
124
- "$ref": "#/definitions/HostedZoneDomain"
125
- },
126
- "cors": {
127
- "$ref": "#/definitions/CorsHeader"
128
- },
129
- "lambdas": {
130
- "$ref": "#/definitions/LambdaRoutesConfig"
131
- }
132
- },
133
- "required": [
134
- "apiDomain",
135
- "hostedZoneDomain",
136
- "lambdas"
137
- ]
138
- },
139
- "APIDomain": {
140
- "type": "string",
141
- "description": "The domain name that the API should be deployed to (e.g. api.mysite.com)",
142
- "title": "API Domain",
143
- "pattern": "^[^\\s]*"
144
- },
145
- "HostedZoneDomain": {
146
- "type": "string",
147
- "description": "The domain name of the Route 53 hosted zone that the domain for this API should be added to.",
148
- "title": "Hosted Zone Domain",
149
- "pattern": "^[^\\s]*"
150
- },
151
- "CorsHeader": {
152
- "type": "string",
153
- "description": "Optional URL for an UI that should be allowed to access this server.",
154
- "title": "CORS Header",
155
- "pattern": "^[^\\s]*"
156
- },
157
- "LambdaRoutesConfig": {
158
- "type": "object",
159
- "additionalProperties": {
160
- "$ref": "#/definitions/LambdaRouteConfig"
161
- }
162
- },
163
- "LambdaRouteConfig": {
164
- "type": "object",
165
- "properties": {
166
- "function_name": {
167
- "type": "string"
168
- },
169
- "route": {
170
- "type": "string"
171
- }
172
- },
173
- "required": [
174
- "function_name",
175
- "route"
176
- ],
177
- "additionalProperties": false
178
- },
179
- "TerraformVariables": {
180
- "type": "array",
181
- "items": {
182
- "$ref": "#/definitions/TerraformVariable"
183
- },
184
- "description": "Define which of the deployment variables will be made available for terraform.",
185
- "title": "Terraform Variables"
186
- },
187
- "TerraformVariable": {
188
- "type": "string",
189
- "description": "Name of the property that should be converted into a Terraform variable.",
190
- "title": "Terraform Variable"
191
- },
192
- "TerraformStateKey": {
193
- "type": "string",
194
- "description": "Key used for Terraform state persisted in Terraform state bucket.\n\nWill be auto-generated upon first deployment if not provided.",
195
- "title": "Terraform State Key"
196
- },
197
- "TerraformVersion": {
198
- "type": "string",
199
- "enum": [
200
- "0.12",
201
- "0.13",
202
- "0.14",
203
- "0.15",
204
- "1.0",
205
- "1.1"
206
- ],
207
- "description": "Version of Terraform that the remote state for this deployment was created with.\n\nGo to the next version using `yarn infra upgrade [deploymentName] [targetVersion]`. Note that Terraform versions should only be increased one at a time, so for instance you can go from v0.12 to v0.13 but not from v0.12 to v0.14.",
208
- "default": "0.12"
209
- },
210
- "AWSDeploymentRegion": {
211
- "type": "string",
212
- "enum": [
213
- "us-east-1",
214
- "us-east-2",
215
- "us-west-1",
216
- "us-west-2",
217
- "af-south-1",
218
- "ap-east-1",
219
- "ap-south-1",
220
- "ap-northeast-3",
221
- "ap-northeast-2",
222
- "ap-southeast-1",
223
- "ap-southeast-2",
224
- "ap-northeast-1",
225
- "ca-central-1",
226
- "eu-central-1",
227
- "eu-west-1",
228
- "eu-west-2",
229
- "eu-south-1",
230
- "eu-west-3",
231
- "eu-north-1",
232
- "me-south-1",
233
- "sa-east-1"
234
- ],
235
- "description": "AWS region that infrastructure should be deployed to.",
236
- "title": "AWS Deployment Region"
237
- },
238
- "AWSUserName": {
239
- "type": "string",
240
- "description": "Name of the AWS user that is used to perform the deployment.",
241
- "title": "AWS User Name"
242
- }
243
- }
244
- }
@@ -1,23 +0,0 @@
1
- import path from 'path';
2
- import { buildLambdas } from './../src/templateLambdaApiBuild';
3
- import { RouteType } from '@goldstack/utils-aws-lambda';
4
-
5
- const fileToBuild = path.resolve('./testData/build-test/index.ts');
6
-
7
- (async () => {
8
- await buildLambdas({
9
- routesDir: './testData/build-test',
10
- configs: [
11
- {
12
- path: '/index',
13
- relativeFilePath: 'index.ts',
14
- name: 'test-lambda-index',
15
- absoluteFilePath: fileToBuild,
16
- route: 'ANY /',
17
- type: RouteType.FUNCTION,
18
- },
19
- ],
20
- });
21
- })().then(() => {
22
- console.log('done');
23
- });
@@ -1,3 +0,0 @@
1
- import { run } from '@goldstack/utils-package-config-generate';
2
-
3
- run(process.argv);
@@ -1,97 +0,0 @@
1
- import {
2
- readLambdaConfig,
3
- generateFunctionName,
4
- } from '@goldstack/utils-aws-lambda';
5
- import assert from 'assert';
6
- import { generateLambdaConfig } from './generateLambdaConfig';
7
- import { LambdaApiDeployment } from './templateLambdaApi';
8
- import { getOutDirForLambda } from './templateLambdaApiBuild';
9
-
10
- const dummyDeployment: LambdaApiDeployment = {
11
- awsRegion: 'ap-east-1',
12
- awsUser: 'dummy',
13
- configuration: {
14
- lambdaNamePrefix: 'test-lambdas',
15
- apiDomain: 'domain',
16
- hostedZoneDomain: 'domain',
17
- lambdas: {},
18
- },
19
- name: 'test',
20
- };
21
-
22
- describe('Generate Lambda config', () => {
23
- const routesConfig = readLambdaConfig('./testData/routes-test');
24
- const config = generateLambdaConfig(dummyDeployment, routesConfig);
25
- test('Should render config for Terraform', () => {
26
- assert(config['default'].function_name);
27
- assert(
28
- config['ANY /folder/nested'].function_name.indexOf(
29
- dummyDeployment.configuration.lambdaNamePrefix || 'fail'
30
- ) !== -1
31
- );
32
- });
33
- test('Should determine correct output dirs for dist', () => {
34
- const nestedRoute = routesConfig.find((e) => e.path === '/folder/nested');
35
- assert(nestedRoute);
36
- const dir = getOutDirForLambda(nestedRoute);
37
- assert(dir === './distLambda/folder/nested');
38
- });
39
- test('Should determine path parametmers for file names', () => {
40
- const nestedRoute = routesConfig.find(
41
- (e) => e.path === '/folder/{pathparam}'
42
- );
43
- assert(nestedRoute);
44
- const functionName = generateFunctionName(
45
- dummyDeployment.configuration.lambdaNamePrefix,
46
- nestedRoute
47
- );
48
- assert(functionName.indexOf('folder') !== -1);
49
- assert(functionName.indexOf('{') === -1);
50
- assert(functionName.indexOf('}') === -1);
51
- });
52
- test('Should determine path parametmers for folder names', () => {
53
- const nestedRoute = routesConfig.find(
54
- (e) => e.path === '/resource/{path}/object'
55
- );
56
- assert(nestedRoute);
57
- const functionName = generateFunctionName(
58
- dummyDeployment.configuration.lambdaNamePrefix,
59
- nestedRoute
60
- );
61
- assert(functionName.indexOf('object') !== -1);
62
- assert(functionName.indexOf('resource') !== -1);
63
- assert(functionName.indexOf('{') === -1);
64
- assert(functionName.indexOf('}') === -1);
65
- });
66
- test('Should provide a correct path for a nested index file', () => {
67
- const nestedRoute = routesConfig.find((e) => e.path === '/health');
68
- assert(nestedRoute);
69
-
70
- const functionName = generateFunctionName(
71
- dummyDeployment.configuration.lambdaNamePrefix,
72
- nestedRoute
73
- );
74
- expect(functionName).toContain('health');
75
- });
76
- test('Should provide a correct path for a file in the API root', () => {
77
- const nestedRoute = routesConfig.find((e) => e.path === '/resource');
78
- assert(nestedRoute);
79
-
80
- const functionName = generateFunctionName(
81
- dummyDeployment.configuration.lambdaNamePrefix,
82
- nestedRoute
83
- );
84
- assert(functionName.match(/resource/g)?.length === 1);
85
- });
86
- test('Should hash long names', () => {
87
- const nestedRoute = routesConfig.find((e) => e.path === '/resource');
88
- assert(nestedRoute);
89
-
90
- const functionName = generateFunctionName(
91
- 'very_long_names_should_end_with_a_hash_and_never_be_longer_than_64_characters',
92
- nestedRoute
93
- );
94
- expect(functionName.length <= 64).toBeTruthy();
95
- expect(functionName.indexOf('characters') === -1).toBe(true);
96
- });
97
- });
@@ -1,37 +0,0 @@
1
- import {
2
- LambdaConfig,
3
- generateFunctionName,
4
- } from '@goldstack/utils-aws-lambda';
5
- import {
6
- LambdaRoutesConfig,
7
- LambdaApiDeployment,
8
- } from './types/LambdaApiPackage';
9
-
10
- export const generateLambdaConfig = (
11
- deployment: LambdaApiDeployment,
12
- config: LambdaConfig[]
13
- ): LambdaRoutesConfig => {
14
- return config.reduce((last, curr) => {
15
- let id = curr.route;
16
- if (id === '$default') {
17
- id = 'default';
18
- }
19
- last[`${id}`] = {
20
- function_name: generateFunctionName(
21
- deployment.configuration.lambdaNamePrefix,
22
- curr
23
- ),
24
- route: curr.route,
25
- };
26
- return last;
27
- }, {});
28
- };
29
-
30
- export const validateDeployment = (config: LambdaRoutesConfig): boolean => {
31
- let valid = true;
32
- for (const e of Object.entries(config)) {
33
- valid = valid && e[0].length > 0;
34
- valid = valid && !!e[1].function_name && e[1].function_name.length > 0;
35
- }
36
- return valid;
37
- };
@@ -1,88 +0,0 @@
1
- import { buildCli, buildDeployCommands } from '@goldstack/utils-package';
2
- import { wrapCli } from '@goldstack/utils-cli';
3
- import { infraCommands } from '@goldstack/utils-terraform';
4
- import { deployCli } from './templateLambdaApiDeploy';
5
- import { terraformAwsCli } from '@goldstack/utils-terraform-aws';
6
- import { PackageConfig } from '@goldstack/utils-package-config';
7
- import { writePackageConfig } from '@goldstack/utils-package';
8
- export * from './types/LambdaApiPackage';
9
- import yargs from 'yargs';
10
- import fs from 'fs';
11
- import {
12
- LambdaApiPackage,
13
- LambdaApiDeployment,
14
- } from './types/LambdaApiPackage';
15
- import { readLambdaConfig } from '@goldstack/utils-aws-lambda';
16
- import {
17
- generateLambdaConfig,
18
- validateDeployment,
19
- } from './generateLambdaConfig';
20
- import { defaultRoutesPath } from './templateLambdaConsts';
21
- import { buildLambdas } from './templateLambdaApiBuild';
22
-
23
- export const run = async (args: string[]): Promise<void> => {
24
- await wrapCli(async () => {
25
- const argv = buildCli({
26
- yargs,
27
- deployCommands: buildDeployCommands(),
28
- infraCommands: infraCommands(),
29
- })
30
- .command('build [deployment]', 'Build all lambdas', () => {
31
- return yargs.positional('deployment', {
32
- type: 'string',
33
- describe: 'Name of the deployment this command should be applied to',
34
- default: '',
35
- });
36
- })
37
- .help().argv;
38
-
39
- const packageConfig = new PackageConfig<
40
- LambdaApiPackage,
41
- LambdaApiDeployment
42
- >({
43
- packagePath: './',
44
- });
45
-
46
- const config = packageConfig.getConfig();
47
-
48
- // update routes
49
- if (!fs.existsSync('./src/routes')) {
50
- throw new Error(
51
- 'Please specify lambda function handlers in ./src/routes so that API Gateway route configuration can be generated.'
52
- );
53
- }
54
- const lambdaRoutes = readLambdaConfig(defaultRoutesPath);
55
- config.deployments = config.deployments.map((e) => {
56
- const lambdasConfigs = generateLambdaConfig(e, lambdaRoutes);
57
- e.configuration.lambdas = lambdasConfigs;
58
- validateDeployment(e.configuration.lambdas);
59
- return e;
60
- });
61
- writePackageConfig(config);
62
-
63
- const command = argv._[0];
64
- const [, , , ...opArgs] = args;
65
-
66
- if (command === 'infra') {
67
- await terraformAwsCli(opArgs);
68
- return;
69
- }
70
-
71
- if (command === 'build') {
72
- await buildLambdas({
73
- routesDir: defaultRoutesPath,
74
- configs: lambdaRoutes,
75
- lambdaNamePrefix: packageConfig.getDeployment(opArgs[0]).configuration
76
- .lambdaNamePrefix,
77
- });
78
- return;
79
- }
80
-
81
- if (command === 'deploy') {
82
- await deployCli(packageConfig.getDeployment(opArgs[0]), lambdaRoutes);
83
- return;
84
- }
85
-
86
- throw new Error('Unknown command: ' + command);
87
- });
88
- };
@@ -1,49 +0,0 @@
1
- import { RouteType } from '@goldstack/utils-aws-lambda';
2
- import { read } from '@goldstack/utils-sh';
3
- import path from 'path';
4
- import { buildLambdas } from './templateLambdaApiBuild';
5
- import fs from 'fs';
6
-
7
- jest.setTimeout(30000);
8
-
9
- describe('Testing lambda build', () => {
10
- it('Should build lambda', async () => {
11
- const fileToBuild = path.resolve('./testData/build-test/index.ts');
12
- expect(fs.existsSync(fileToBuild)).toEqual(true);
13
- await buildLambdas({
14
- routesDir: './testData/build-test',
15
- configs: [
16
- {
17
- path: '/index',
18
- relativeFilePath: 'index.ts',
19
- name: 'test-lambda-index',
20
- absoluteFilePath: fileToBuild,
21
- route: 'ANY /',
22
- type: RouteType.FUNCTION,
23
- },
24
- ],
25
- });
26
- const generated = read('./distLambda/index/lambda.js');
27
- expect(generated.length).toBeGreaterThan(100);
28
- });
29
-
30
- it('Should build lambda with custom esbuild config', async () => {
31
- await buildLambdas({
32
- routesDir: './testData/build-test',
33
- configs: [
34
- {
35
- path: '/customBuild',
36
- relativeFilePath: 'customBuild.ts',
37
- name: 'test-lambda-customBuild',
38
- absoluteFilePath: path.resolve(
39
- './testData/build-test/customBuild.ts'
40
- ),
41
- route: 'ANY /',
42
- type: RouteType.FUNCTION,
43
- },
44
- ],
45
- });
46
- const generated = read('./distLambda/customBuild/lambda.js');
47
- expect(generated).toContain('Custom config in operation');
48
- });
49
- });
@@ -1,72 +0,0 @@
1
- import { build, BuildOptions } from 'esbuild';
2
- import { pnpPlugin } from '@yarnpkg/esbuild-plugin-pnp';
3
- import {
4
- generateFunctionName,
5
- LambdaConfig,
6
- } from '@goldstack/utils-aws-lambda';
7
- import {
8
- changeExtension,
9
- mkdir,
10
- readToType,
11
- rmSafe,
12
- write,
13
- } from '@goldstack/utils-sh';
14
- import { LambdaApiDeployment } from './types/LambdaApiPackage';
15
-
16
- export const getOutDirForLambda = (config: LambdaConfig): string => {
17
- if (config.path === '$default') {
18
- return `./distLambda/${config.path}`;
19
- }
20
- return `./distLambda${config.path}`;
21
- };
22
-
23
- export const getOutFileForLambda = (config: LambdaConfig): string => {
24
- return `${getOutDirForLambda(config)}/lambda.js`;
25
- };
26
-
27
- export const buildLambdas = async ({
28
- routesDir,
29
- configs,
30
- lambdaNamePrefix,
31
- }: {
32
- routesDir: string;
33
- configs: LambdaConfig[];
34
- lambdaNamePrefix?: string;
35
- }): Promise<void> => {
36
- const esbuildConfig = readToType<BuildOptions>('./esbuild.config.json');
37
-
38
- await rmSafe('./distLambda');
39
- mkdir('-p', './distLambda/zips');
40
- for await (const config of configs) {
41
- mkdir('-p', getOutDirForLambda(config));
42
- const esbuildLocalPath = changeExtension(
43
- `${routesDir}/${config.relativeFilePath}`,
44
- '.esbuild.config.json'
45
- );
46
- const functionName = generateFunctionName(lambdaNamePrefix, config);
47
- const localEsbuildConfig = readToType<BuildOptions>(esbuildLocalPath);
48
-
49
- const res = await build({
50
- plugins: [pnpPlugin()],
51
- bundle: true,
52
- entryPoints: [`${routesDir}/${config.relativeFilePath}`],
53
- external: ['aws-sdk', 'mock-aws-s3', 'testcontainers'], // mock-aws-s3 from s3 template, testcontainers from dynamodb template
54
- minify: true,
55
- platform: 'node',
56
- format: 'cjs',
57
- target: 'node16.0',
58
- sourcemap: true,
59
- outfile: getOutFileForLambda(config),
60
- metafile: true,
61
- ...esbuildConfig,
62
- ...localEsbuildConfig,
63
- });
64
- if (!res.metafile) {
65
- throw new Error(`Metafile for ${functionName} not defined.`);
66
- }
67
- write(
68
- JSON.stringify(res.metafile),
69
- `./distLambda/zips/${functionName}.meta.json`
70
- );
71
- }
72
- };
@@ -1,54 +0,0 @@
1
- import { LambdaApiDeployment } from './types/LambdaApiPackage';
2
- import { getAWSUser } from '@goldstack/infra-aws';
3
- import {
4
- deployFunction,
5
- LambdaConfig,
6
- generateFunctionName,
7
- } from '@goldstack/utils-aws-lambda';
8
-
9
- import { readLambdaConfig } from '@goldstack/utils-aws-lambda';
10
- import { defaultRoutesPath } from './templateLambdaConsts';
11
-
12
- import { mkdir, rmSafe } from '@goldstack/utils-sh';
13
- import { getOutDirForLambda } from './templateLambdaApiBuild';
14
-
15
- interface DeployLambdaParams {
16
- deployment: LambdaApiDeployment;
17
- config: LambdaConfig[];
18
- }
19
-
20
- export const deployLambdas = async (
21
- params: DeployLambdaParams
22
- ): Promise<void> => {
23
- const lambdaConfig = readLambdaConfig(defaultRoutesPath);
24
-
25
- const operations = lambdaConfig.map(async (config) => {
26
- const functionName = generateFunctionName(
27
- params.deployment.configuration.lambdaNamePrefix,
28
- config
29
- );
30
- console.log(`[${functionName}]: Starting deployment`);
31
- const functionDir = getOutDirForLambda(config);
32
- mkdir('-p', functionDir);
33
- const targetArchive = `./distLambda/zips/${functionName}.zip`;
34
- await deployFunction({
35
- targetArchiveName: targetArchive,
36
- lambdaPackageDir: functionDir,
37
- awsCredentials: await getAWSUser(params.deployment.awsUser),
38
- region: params.deployment.awsRegion,
39
- functionName,
40
- });
41
- console.log(`[${functionName}]: Deployment completed`);
42
- });
43
- await Promise.all(operations);
44
- };
45
-
46
- export const deployCli = async (
47
- deployment: LambdaApiDeployment,
48
- config: LambdaConfig[]
49
- ): Promise<void> => {
50
- await deployLambdas({
51
- deployment,
52
- config,
53
- });
54
- };
@@ -1 +0,0 @@
1
- export const defaultRoutesPath = './src/routes';