diff --git a/lib/plugins/aws/deployFunction.js b/lib/plugins/aws/deployFunction.js index 3863b2888..7ab014dd9 100644 --- a/lib/plugins/aws/deployFunction.js +++ b/lib/plugins/aws/deployFunction.js @@ -67,20 +67,21 @@ class AwsDeployFunction { FunctionName: this.options.functionObj.name, }; - try { - const result = await this.provider.request('Lambda', 'getFunction', params); + const result = await (async () => { + try { + return await this.provider.request('Lambda', 'getFunction', params); + } catch (error) { + const errorMessage = [ + `The function "${this.options.function}" you want to update is not yet deployed.`, + ' Please run "serverless deploy" to deploy your service.', + ' After that you can redeploy your services functions with the', + ' "serverless deploy function" command.', + ].join(''); + throw new ServerlessError(errorMessage); + } + })(); - this.serverless.service.provider.remoteFunctionData = result; - return result; - } catch { - const errorMessage = [ - `The function "${this.options.function}" you want to update is not yet deployed.`, - ' Please run "serverless deploy" to deploy your service.', - ' After that you can redeploy your services functions with the', - ' "serverless deploy function" command.', - ].join(''); - throw new ServerlessError(errorMessage); - } + if (result) this.serverless.service.provider.remoteFunctionData = result; } checkIfFunctionChangesBetweenImageAndHandler() {