From 8ea06053a22c1cf51fa8d1e736ebb20476499dfd Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Tue, 14 Jun 2016 20:03:56 +0200 Subject: [PATCH] Fix s3 is undefined bug --- lib/plugins/awsCompileS3Events/awsCompileS3Events.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/plugins/awsCompileS3Events/awsCompileS3Events.js b/lib/plugins/awsCompileS3Events/awsCompileS3Events.js index 797015a49..12d7018f7 100644 --- a/lib/plugins/awsCompileS3Events/awsCompileS3Events.js +++ b/lib/plugins/awsCompileS3Events/awsCompileS3Events.js @@ -42,7 +42,9 @@ class AwsCompileS3Events { this.serverless.service.getAllFunctions().forEach((functionName) => { const s3BucketObject = this.serverless.service.getFunction(functionName); - if (s3BucketObject.events.aws.s3) { + // checking all three levels in the obj tree + // to avoid "can't read property of undefined" error + if (s3BucketObject.events && s3BucketObject.events.aws && s3BucketObject.events.aws.s3) { // iterate over all defined buckets s3BucketObject.events.aws.s3.forEach((bucketName) => { // 1. create the S3 bucket with the corresponding notification