Skip to content

Commit 98292fd

Browse files
committed
feat: add custom runtime support based on the defined runtime
1 parent 0665e63 commit 98292fd

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

lib/plugins/aws/custom-resources/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ async function addCustomResourceToService(awsProvider, resourceName, iamRoleStat
162162
});
163163
}
164164

165+
const runtimeVersion = providerConfig.runtime ? providerConfig.runtime : 'nodejs18.x';
166+
165167
const customResourceFunction = {
166168
Type: 'AWS::Lambda::Function',
167169
Properties: {
@@ -172,7 +174,7 @@ async function addCustomResourceToService(awsProvider, resourceName, iamRoleStat
172174
FunctionName: absoluteFunctionName,
173175
Handler,
174176
MemorySize: 1024,
175-
Runtime: 'nodejs18.x',
177+
Runtime: runtimeVersion,
176178
Timeout: 180,
177179
},
178180
DependsOn: [],

test/unit/lib/plugins/aws/custom-resources/index.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,59 @@ describe('#addCustomResourceToService()', () => {
347347
Resources.CustomDashresourceDashexistingDashs3LambdaFunction.Properties.FunctionName.length
348348
).to.be.below(65);
349349
});
350+
351+
it('should use defined runtime', async () => {
352+
serverless.service.provider.runtime = 'nodejs22.x';
353+
await Promise.all([
354+
// add the custom S3 resource
355+
addCustomResourceToService(provider, 's3', [
356+
...iamRoleStatements,
357+
{
358+
Effect: 'Allow',
359+
Resource: 'arn:aws:s3:::some-bucket',
360+
Action: ['s3:PutBucketNotification', 's3:GetBucketNotification'],
361+
},
362+
]),
363+
// add the custom Cognito User Pool resource
364+
addCustomResourceToService(provider, 'cognitoUserPool', [
365+
...iamRoleStatements,
366+
{
367+
Effect: 'Allow',
368+
Resource: '*',
369+
Action: [
370+
'cognito-idp:ListUserPools',
371+
'cognito-idp:DescribeUserPool',
372+
'cognito-idp:UpdateUserPool',
373+
],
374+
},
375+
]),
376+
// add the custom Event Bridge resource
377+
addCustomResourceToService(provider, 'eventBridge', [
378+
...iamRoleStatements,
379+
{
380+
Effect: 'Allow',
381+
Resource: 'arn:aws:events:*:*:rule/some-rule',
382+
Action: [
383+
'events:PutRule',
384+
'events:RemoveTargets',
385+
'events:PutTargets',
386+
'events:DeleteRule',
387+
],
388+
},
389+
{
390+
Action: ['events:CreateEventBus', 'events:DeleteEventBus'],
391+
Effect: 'Allow',
392+
Resource: 'arn:aws:events:*:*:event-bus/some-event-bus',
393+
},
394+
]),
395+
]);
396+
397+
const { Resources } = serverless.service.provider.compiledCloudFormationTemplate;
398+
399+
expect(Resources.CustomDashresourceDashexistingDashs3LambdaFunction.Properties.Runtime).to.equal('nodejs22.x');
400+
expect(Resources.CustomDashresourceDashexistingDashcupLambdaFunction.Properties.Runtime).to.equal('nodejs22.x');
401+
expect(Resources.CustomDashresourceDasheventDashbridgeLambdaFunction.Properties.Runtime).to.equal('nodejs22.x');
402+
});
350403
});
351404

352405
describe('test/unit/lib/plugins/aws/customResources/index.test.js', () => {

0 commit comments

Comments
 (0)