diff --git a/lib/plugins/aws/deploy/compile/functions/index.js b/lib/plugins/aws/deploy/compile/functions/index.js index 88b374e23..143878400 100644 --- a/lib/plugins/aws/deploy/compile/functions/index.js +++ b/lib/plugins/aws/deploy/compile/functions/index.js @@ -86,6 +86,12 @@ class AwsCompileFunctions { this.serverless.service.provider.environment, functionObject.environment ) + + for(var key in newFunction.Properties.Environment.Variables){ + // I pulled this from the bash man pages + if(!key.match(/^[A-Za-z_][a-zA-Z0-9_]*$/)){ + throw new Error("Invalid characters in environment variable"); + } } if ('role' in functionObject) { diff --git a/lib/plugins/aws/deploy/compile/functions/tests/index.js b/lib/plugins/aws/deploy/compile/functions/tests/index.js index b1c9abf55..d6d5a6ccf 100644 --- a/lib/plugins/aws/deploy/compile/functions/tests/index.js +++ b/lib/plugins/aws/deploy/compile/functions/tests/index.js @@ -420,6 +420,22 @@ describe('AwsCompileFunctions', () => { }; }); + + it('should throw if invalid environment variable name', () => { + awsCompileFunctions.serverless.service.functions = { + func: { + handler: 'func.function.handler', + name: 'new-service-dev-func', + environment: { + '1test1': 'test1', + test2: 'test2', + }, + }, + }; + + expect(() => awsCompileFunctions.compileFunctions()).to.throw(Error); + }); + it('should consider function based config when creating a function resource', () => { awsCompileFunctions.serverless.service.functions = { func: {