Skip to content

Commit 533f1c0

Browse files
committed
feat: deploy action create lambda OK
Signed-off-by: seven <zilisheng1996@gmail.com>
1 parent cd0a587 commit 533f1c0

File tree

10 files changed

+51
-59
lines changed

10 files changed

+51
-59
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/coverage/
55
/.vscode/
66
.DS_Store
7+
/artifacts/

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
.prettierrc
33
jest.config.js
44
tsconfig.json
5+
Dockerfile
56

67
.idea/
78
.github/
9+
.husky/
810
coverage/
911
src/
1012
tests/
1113
docs/
14+
artifacts/
15+
scripts/
1216
# Ignore all .d.ts files except index.d.ts
1317
*.d.ts
1418
!index.d.ts

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@geek-fun/serverlessinsight",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "Full life cycle cross providers serverless application management for your fast-growing business.",
55
"homepage": "https://serverlessinsight.geekfun.club",
66
"main": "dist/src/index.js",

src/common/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './provider';
33
export * from './logger';
44
export * from './getVersion';
55
export * from './rosClient';
6+
export * from './actionContext';

src/iac/parse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { validateYaml } from './iacSchema';
55

66
const mapToArr = (obj: Record<string, Record<string, unknown> | string>) => {
77
return Object.entries(obj).map(([key, value]) =>
8-
typeof value === 'string' ? { [key]: value } : { id: key, ...value },
8+
typeof value === 'string' ? { [key]: value } : { key, ...value },
99
);
1010
};
1111

src/iac/resource.ts

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

src/stack/deploy.ts

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,49 @@ import * as ros from '@alicloud/ros-cdk-core';
22
import * as fc from '@alicloud/ros-cdk-fc';
33
import { ActionContext, ServerlessIac } from '../types';
44
import { printer, rosStackDeploy } from '../common';
5+
import path from 'node:path';
6+
import * as fs from 'node:fs';
7+
8+
const resolveCode = (location: string): string => {
9+
const filePath = path.resolve(process.cwd(), location);
10+
const fileContent = fs.readFileSync(filePath);
11+
12+
return fileContent.toString('base64');
13+
};
514

615
export class IacStack extends ros.Stack {
716
constructor(scope: ros.Construct, iac: ServerlessIac, props?: ros.StackProps) {
817
super(scope, iac.service, props);
918
new ros.RosInfo(this, ros.RosInfo.description, 'This is the simple ros cdk app example.');
10-
iac.functions.map(
11-
(fnc) =>
12-
new fc.RosFunction(
13-
this,
14-
fnc.name,
15-
{
16-
functionName: fnc.name,
17-
serviceName: `${fnc.name}-service`,
18-
handler: fnc.handler,
19-
runtime: fnc.runtime,
20-
memorySize: fnc.memory,
21-
timeout: fnc.timeout,
22-
environmentVariables: fnc.environment,
23-
code: {
24-
zipFile:
25-
'exports.handler = function(event, context, callback) { callback(null, "Hello World"); }',
26-
},
27-
},
28-
false,
29-
),
19+
const service = new fc.RosService(
20+
this,
21+
`${iac.service}-service`,
22+
{
23+
serviceName: `${iac.service}-service`,
24+
},
25+
true,
3026
);
27+
28+
iac.functions.forEach((fnc) => {
29+
const func = new fc.RosFunction(
30+
this,
31+
fnc.key,
32+
{
33+
functionName: fnc.name,
34+
serviceName: service.serviceName,
35+
handler: fnc.handler,
36+
runtime: fnc.runtime,
37+
memorySize: fnc.memory,
38+
timeout: fnc.timeout,
39+
environmentVariables: fnc.environment,
40+
code: {
41+
zipFile: resolveCode(fnc.code),
42+
},
43+
},
44+
true,
45+
);
46+
func.addDependsOn(service);
47+
});
3148
}
3249
}
3350

src/types.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,17 @@ type Stages = {
1212

1313
export type IacFunction = {
1414
name: string;
15+
key: string;
1516
runtime: string;
1617
handler: string;
17-
zip: string;
18+
code: string;
1819
memory: number;
1920
timeout: number;
2021
environment: {
2122
[key: string]: string;
2223
};
2324
};
2425

25-
type Functions = {
26-
[key: string]: IacFunction;
27-
};
28-
2926
export type Event = {
3027
type: string;
3128
source: string;
@@ -50,7 +47,7 @@ export type RawServerlessIac = {
5047
stages: Stages;
5148
service: string;
5249
tags: Tags;
53-
functions: Functions;
50+
functions: { [key: string]: IacFunction };
5451
events: Events;
5552
};
5653

tests/fixtures/serverless-insignt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ functions:
2020
name: insight-poc-fn
2121
runtime: nodejs14
2222
handler: index.handler
23-
code: artifact.zip
23+
code: artifacts/artifact.zip
2424
memory: 512
2525
timeout: 10
2626
environment:

0 commit comments

Comments
 (0)