Skip to content

Commit 1d5d3ee

Browse files
committed
feat(function): add go, python runtimes to defineFunction
1 parent 15bf421 commit 1d5d3ee

File tree

10 files changed

+366
-74
lines changed

10 files changed

+366
-74
lines changed

package-lock.json

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

packages/backend-function/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"@aws-amplify/backend-output-schemas": "^1.1.0",
2222
"@aws-amplify/backend-output-storage": "^1.0.1",
2323
"@aws-amplify/plugin-types": "^1.0.0",
24+
"@aws-cdk/aws-lambda-go-alpha": "^2.141.0-alpha.0",
25+
"@aws-cdk/aws-lambda-python-alpha": "^2.144.0-alpha.0",
2426
"execa": "^8.0.1"
2527
},
2628
"devDependencies": {

packages/backend-function/src/factory.test.ts

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from '@aws-amplify/backend-platform-test-stubs';
1414
import { defaultLambda } from './test-assets/default-lambda/resource.js';
1515
import { Template } from 'aws-cdk-lib/assertions';
16-
import { NodeVersion, defineFunction } from './factory.js';
16+
import { RuntimeType, defineFunction } from './factory.js';
1717
import { lambdaWithDependencies } from './test-assets/lambda-with-dependencies/resource.js';
1818
import { Runtime } from 'aws-cdk-lib/aws-lambda';
1919
import { Policy, PolicyStatement } from 'aws-cdk-lib/aws-iam';
@@ -273,7 +273,7 @@ void describe('AmplifyFunctionFactory', () => {
273273
void it('sets valid runtime', () => {
274274
const lambda = defineFunction({
275275
entry: './test-assets/default-lambda/handler.ts',
276-
runtime: 16,
276+
runtime: 'NODEJS_16_X',
277277
}).getInstance(getInstanceProps);
278278
const template = Template.fromStack(Stack.of(lambda.resources.lambda));
279279

@@ -282,6 +282,78 @@ void describe('AmplifyFunctionFactory', () => {
282282
});
283283
});
284284

285+
void it('sets valid go runtime', () => {
286+
const lambda = defineFunction({
287+
entry: './test-assets/golang-lambda/',
288+
runtime: 'GO_1_X_PROVIDED_AL2023',
289+
}).getInstance(getInstanceProps);
290+
const template = Template.fromStack(Stack.of(lambda.resources.lambda));
291+
292+
template.hasResourceProperties('AWS::Lambda::Function', {
293+
Runtime: Runtime.PROVIDED_AL2023.name,
294+
});
295+
});
296+
297+
void it('sets not valid go runtime', () => {
298+
assert.throws(
299+
() =>
300+
defineFunction({
301+
entry: './test-assets/golang-lambda/',
302+
runtime: 'GO_1_X' as RuntimeType,
303+
}).getInstance(getInstanceProps),
304+
new Error(
305+
'runtime must be one of the following: NODEJS_16_X, NODEJS_18_X, NODEJS_20_X, GO_1_X_PROVIDED_AL2023, PYTHON_3_8, PYTHON_3_9, PYTHON_3_10, PYTHON_3_11, PYTHON_3_12'
306+
)
307+
);
308+
});
309+
310+
void it('sets not valid go runtime, entry empty', () => {
311+
assert.throws(
312+
() =>
313+
defineFunction({
314+
runtime: 'GO_1_X_PROVIDED_AL2023',
315+
}).getInstance(getInstanceProps),
316+
new Error(
317+
'entry must be set for custom runtime "GO_1_X_PROVIDED_AL2023"'
318+
)
319+
);
320+
});
321+
322+
void it('sets valid python runtime', () => {
323+
const lambda = defineFunction({
324+
entry: './test-assets/python-lambda/',
325+
runtime: 'PYTHON_3_8',
326+
}).getInstance(getInstanceProps);
327+
const template = Template.fromStack(Stack.of(lambda.resources.lambda));
328+
329+
template.hasResourceProperties('AWS::Lambda::Function', {
330+
Runtime: Runtime.PYTHON_3_8.name,
331+
});
332+
});
333+
334+
void it('sets not valid python runtime not valid runtime version', () => {
335+
assert.throws(
336+
() =>
337+
defineFunction({
338+
entry: './test-assets/python-lambda/',
339+
runtime: 'PYTHON_3_7' as RuntimeType,
340+
}).getInstance(getInstanceProps),
341+
new Error(
342+
'runtime must be one of the following: NODEJS_16_X, NODEJS_18_X, NODEJS_20_X, GO_1_X_PROVIDED_AL2023, PYTHON_3_8, PYTHON_3_9, PYTHON_3_10, PYTHON_3_11, PYTHON_3_12'
343+
)
344+
);
345+
});
346+
347+
void it('sets not valid python runtime empty entry', () => {
348+
assert.throws(
349+
() =>
350+
defineFunction({
351+
runtime: 'PYTHON_3_8',
352+
}).getInstance(getInstanceProps),
353+
new Error('entry must be set for custom runtime "PYTHON_3_8"')
354+
);
355+
});
356+
285357
void it('defaults to oldest LTS runtime', () => {
286358
const lambda = defineFunction({
287359
entry: './test-assets/default-lambda/handler.ts',
@@ -298,9 +370,11 @@ void describe('AmplifyFunctionFactory', () => {
298370
() =>
299371
defineFunction({
300372
entry: './test-assets/default-lambda/handler.ts',
301-
runtime: 14 as NodeVersion,
373+
runtime: 'NODEJS_14_X' as RuntimeType,
302374
}).getInstance(getInstanceProps),
303-
new Error('runtime must be one of the following: 16, 18, 20')
375+
new Error(
376+
'runtime must be one of the following: NODEJS_16_X, NODEJS_18_X, NODEJS_20_X, GO_1_X_PROVIDED_AL2023, PYTHON_3_8, PYTHON_3_9, PYTHON_3_10, PYTHON_3_11, PYTHON_3_12'
377+
)
304378
);
305379
});
306380

0 commit comments

Comments
 (0)