5
5
ExistingDirectory ,
6
6
ExistingLambda ,
7
7
NewFromCode ,
8
- // NewFromTemplate,
8
+ NewFromTemplate ,
9
9
RestApiConstructProps ,
10
10
} from './types.js' ;
11
11
@@ -30,7 +30,8 @@ export class RestApiConstruct extends Construct {
30
30
const { path, routes, lambdaEntry } = pathConfig ;
31
31
const source = lambdaEntry . source ;
32
32
33
- // Determine Lambda code source
33
+ // Determine Lambda code source - either ExistingDirectory, NewFromCode, NewFromTemplate,
34
+ // or ExistingLambda (function already exists in aws and does not need to be constructed)
34
35
let code : lambda . AssetCode | lambda . InlineCode =
35
36
lambda . Code . fromInline ( '' ) ;
36
37
if ( 'path' in source ) {
@@ -40,15 +41,15 @@ export class RestApiConstruct extends Construct {
40
41
const src = source as NewFromCode ;
41
42
code = lambda . Code . fromInline ( src . code ) ;
42
43
} else if ( 'template' in source ) {
43
- // const src = source as NewFromTemplate;
44
- // NOTE: You may expand supported templates later
45
- code = lambda . Code . fromInline (
46
- "exports.handler = () => { console.log('Hello World'); };" ,
47
- ) ;
48
- } else {
49
- // fallback to dummy if none matched — should never happen if typing is correct
50
- code = lambda . Code . fromInline ( 'exports.handler = () => {};' ) ;
44
+ //TODO: Expand supported templates later
45
+ const src = source as NewFromTemplate ;
46
+ if ( src . template === 'Hello World' ) {
47
+ code = lambda . Code . fromInline (
48
+ "exports.handler = () => { console.log('Hello World'); };" ,
49
+ ) ;
50
+ }
51
51
}
52
+ //if none of these are true, it's a ExistingLambda type, handled below
52
53
53
54
// Create or reference Lambda function
54
55
let handler : lambda . IFunction ;
@@ -59,7 +60,7 @@ export class RestApiConstruct extends Construct {
59
60
handler = new lambda . Function ( this , `LambdaHandler-${ index } ` , {
60
61
runtime : lambdaEntry . runtime ,
61
62
handler : 'index.handler' ,
62
- code,
63
+ code : code ,
63
64
} ) ;
64
65
}
65
66
0 commit comments