Repository: HyperBrain/serverless-aws-alias (js)

Issue:
Warmup
Hi,
Thanks for this very useful project.
I've add the warmup plugin with the prewarm option.
I've seen the integration in the warmup plugin of the alias var.

I was wondering if it's possible to warmup the new version of the lambda deployed before the alias is changed to point on it.
The aim is to avoid lambda timeout after the alias is changed because of the long coldstart period.

Any ideas ?
Thanks,

Fred.



Pull request description:
Set SERVERLESS_ALIAS during build
Fixes #72 

The warmup plugin (and maybe others as well) uses the SERVERLESS_ALIAS environment variable to determine if the functions are deployed to a specific alias.

Until now the variable was only available at runtime, so the evaluation failed.

It is now set in the validate() function, so that the plugins can easily grab it.

Patch:
diff --git a/lib/validate.js b/lib/validate.js
index de29d14..2f446bb 100644
--- a/lib/validate.js
+++ b/lib/validate.js
@@ -23,6 +23,9 @@ module.exports = {
 		// Make alias available as ${self:provider.alias}
 		this._serverless.service.provider.alias = this._alias;
 
+		// Set SERVERLESS_ALIAS environment variable to let other plugins access it during the build
+		process.env.SERVERLESS_ALIAS = this._alias;
+
 		// Parse and check plugin options
 		if (this._options['alias-resources']) {
 			this._aliasResources = true;


Test patch:
diff --git a/test/validate.test.js b/test/validate.test.js
index 71379d0..6db5359 100644
--- a/test/validate.test.js
+++ b/test/validate.test.js
@@ -56,6 +56,11 @@ describe('#validate()', () => {
 		]));
 	});
 
+	it('should set SERVERLESS_ALIAS', () => {
+		return expect(awsAlias.validate()).to.eventually.be.fulfilled
+		.then(() => expect(process.env.SERVERLESS_ALIAS).to.equal('myStage'));
+	});
+
 	it('should succeed', () => {
 		return expect(awsAlias.validate()).to.eventually.be.fulfilled;
 	});