-
-
Notifications
You must be signed in to change notification settings - Fork 45
Description
Hey guys, it's so great that you released serverless core code to use AWS SDK V3. Thank you for all your efforts. I am pretty sure that after the end of support for AWS SDK V2 on September 8, 2025, many more developers will want to migrate their serverless infrastructure to use your fork.
I have tested it with our real live projects, and unfortunately found that migration to your fork will not be straight forward with SLS_AWS_SDK_V3=1 due to incompatibility issues with serverless plugins which we use. For example our Node.js serverless projects use next plugins:
- serverless-deployment-bucket
- serverless-stack-termination-protection
- serverless-associate-waf
- serverless-prune-plugin
and each of them will throw error mainly due to non existed method in COMMAND_MAP or non existed client for service in CLIENT_MAP. I've found workaround on my side, in short I implemented local serverless plugin which apply monkey path to your provider and extend support of more services and methods. It's not ideal, but gives some further thoughts how it can be improved.
I clearly understand that you are not going to rework hundreds of existing plugins or extend oss-serverless core functionality to support them. But it could be done by community if they will have public API in provider to extend those hardcoded maps.
Solution proposal
I suggest you will add 2 new public methods in AWS provider https://github.com/oss-serverless/serverless/blob/main/lib/plugins/aws/provider.js
registerCommandClassV3(serviceNameV2, methodNameV2, commandClassV3);
registerClientClassV3(serviceNameV2, clientClassV3);
So anyone who will want to fix work of their used plugins will check what services and methods plugin request. Then create local or published serverless plugin to patch work of broken plugin.
Example for serverless-prune-plugin. Let's create oss-serverless-prune-plugin-patch with next code:
'use strict';
// Lambda Commands
const {
DeleteLayerVersionCommand,
DeleteFunctionCommand,
ListAliasesCommand,
ListLayerVersionsCommand,
} = require('@aws-sdk/client-lambda');
const { LambdaClient } = require('@aws-sdk/client-lambda');
class OssServerlessPrunePluginPatch {
/**
* @param serverless
* @param options
*/
constructor(serverless, options) {
this.patched = false;
this.options = options;
this.serverless = serverless;
this.hooks = {
'after:deploy:deploy': this.patch.bind(this),
'before:deploy:deploy': this.patch.bind(this),
'before:package:initialize': this.patch.bind(this),
'before:aws:common:validate:validate': this.patch.bind(this),
};
}
patch() {
if (this.patched) {
return;
}
const provider = this.serverless.getProvider('aws');
if (!provider) {
this.serverless.cli.log('AWS provider not found');
return;
}
provider
.registerCommandClassV3('Lambda', 'deleteLayerVersion', DeleteLayerVersionCommand)
.registerCommandClassV3('Lambda', 'deleteFunction', DeleteFunctionCommand)
.registerCommandClassV3('Lambda', 'listAliases', ListAliasesCommand)
.registerCommandClassV3('Lambda', 'listLayerVersions', ListLayerVersionsCommand);
provider.registerClientClassV3('Lambda', LambdaClient); // just an example
this.patched = true;
}
}
module.exports = OssServerlessPrunePluginPatch;
So in serverless.yml we will be able to patch serverless-prune-plugin
service: my-test-service
useDotenv: true
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
frameworkVersion: ^3.24.1
# Setting the variable resolution mode to a version that will interpret
# StringList ssm parameters as a list of strings
variablesResolutionMode: 20210326
plugins:
- oss-serverless-prune-plugin-patch
- serverless-prune-plugin
...