Multi region deploy plugin

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

This plugin sounds awesome!

What does your serverless.yml look like? The error sounds like it’s coming from a misconfigured http event

1 Like

Issue solved by calling deploy as child process

exec(sls deploy --region ${region})

Awesome. I’ve had to execSync the framework more times than I can count.

One day programatic access will be a first class citizen… one day.

Are you planning on open sourcing the plugin? We’d love to share that with the community at large via the plugin repo https://github.com/serverless/plugins