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