Skip to content

Commit 2fd05fa

Browse files
authored
Merge pull request #3 from bennettsf/lambda-handling
minor lambda fixes
2 parents 8fb298d + 58d0780 commit 2fd05fa

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

packages/rest-api-construct/src/construct.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ExistingDirectory,
66
ExistingLambda,
77
NewFromCode,
8-
// NewFromTemplate,
8+
NewFromTemplate,
99
RestApiConstructProps,
1010
} from './types.js';
1111

@@ -30,7 +30,8 @@ export class RestApiConstruct extends Construct {
3030
const { path, routes, lambdaEntry } = pathConfig;
3131
const source = lambdaEntry.source;
3232

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)
3435
let code: lambda.AssetCode | lambda.InlineCode =
3536
lambda.Code.fromInline('');
3637
if ('path' in source) {
@@ -40,15 +41,15 @@ export class RestApiConstruct extends Construct {
4041
const src = source as NewFromCode;
4142
code = lambda.Code.fromInline(src.code);
4243
} 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+
}
5151
}
52+
//if none of these are true, it's a ExistingLambda type, handled below
5253

5354
// Create or reference Lambda function
5455
let handler: lambda.IFunction;
@@ -59,7 +60,7 @@ export class RestApiConstruct extends Construct {
5960
handler = new lambda.Function(this, `LambdaHandler-${index}`, {
6061
runtime: lambdaEntry.runtime,
6162
handler: 'index.handler',
62-
code,
63+
code: code,
6364
});
6465
}
6566

0 commit comments

Comments
 (0)