My task is to create plugin capable of perform deploys to multiple regions, and if one of regions fails, to perform a rollback on all regions.
I need to find a way to invoke command with options inside serverless plugin.
Tasks of getting previous template and rolling it back are mainly complete, but I hit by an issue with actual deploy.
I found a way to spawn subprocess by calling this.serverless.pluginManager.spawn(‘deploy’),
but I cannot pass a region option. Spawn method has options param, but it is intended only to spawn method by itself.
Also I have dirty hack of setting this.serverless.service.provider.region and chaining deploys continuously:
return this.options.regions
.map(region => {
return () => {
this.log(Starting deployment to ${region}
);
this.setRegion(region);
return this.serverless.pluginManager.spawn(‘deploy’);
};
})
.reduce((prev, curr) => prev.then(curr), Promise.resolve())
It seems to launch deployment with intended region, but unfortunately serverless fails with an internal error:
“ServerlessError: You can only use “origin” or “origins”, but not both at the same time to configure CORS. Please check the docs for more info”
at AwsCompileApigEvents.getCors.
Alternative is to write bash script which would be nasty as I need to manually parse output, analyze if deploy successful and throw away built in plugin concept.
Can anyone spill some light on this?
Thanks,
Dima