@@ -132,13 +132,22 @@ func main() {
132132 log .Fatal ("Failed to download code archives: " + err .Error ())
133133 }
134134
135- // fix permissions of the layers directory for better AWS parity
135+ // set file permissions of the tmp directory for better AWS parity
136+ if err := ChmodRecursively ("/tmp" , 0700 ); err != nil {
137+ log .Warnln ("Could not change file mode recursively of directory /tmp:" , err )
138+ }
139+ // set file permissions of the layers directory for better AWS parity
136140 if err := ChmodRecursively ("/opt" , 0755 ); err != nil {
137141 log .Warnln ("Could not change file mode recursively of directory /opt:" , err )
138142 }
139- // fix permissions of the tmp directory for better AWS parity
140- if err := ChmodRecursively ("/tmp" , 0700 ); err != nil {
141- log .Warnln ("Could not change file mode recursively of directory /tmp:" , err )
143+ // set file permissions of the code directory if at least one layer is present for better AWS parity
144+ // Limitation: hot reloading likely breaks file permission parity for /var/task in combination with layers
145+ // Heuristic for detecting the presence of layers. It might fail for an empty layer or image-based Lambda.
146+ if isDirEmpty , _ := IsDirEmpty ("/opt" ); ! isDirEmpty {
147+ log .Debugln ("Detected layer present" )
148+ if err := ChmodRecursively ("/var/task" , 0755 ); err != nil {
149+ log .Warnln ("Could not change file mode recursively of directory /var/task:" , err )
150+ }
142151 }
143152
144153 // parse CLI args
0 commit comments