Skip to content

Commit 703935c

Browse files
wchengruvalerena
andauthored
valid the bootstraps before passing to NewBootstrapSingleCmd (#45)
* Pull upstream changes 2021/06 (#39) * valid the bootstraps before passing to NewBootstrapSingleCmd * refactor the code to better asign the default value * reformat indents * use function to detect is file exist * minor fix * fix a logical error Co-authored-by: Renato Valenzuela <[email protected]>
1 parent 8af3c67 commit 703935c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

cmd/aws-lambda-rie/main.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,34 @@ func getCLIArgs() (options, []string) {
5656
return opts, args
5757
}
5858

59+
func isBootstrapFileExist(filePath string) bool {
60+
file, err := os.Stat(filePath)
61+
return !os.IsNotExist(err) && !file.IsDir()
62+
}
63+
5964
func getBootstrap(args []string, opts options) (*rapidcore.Bootstrap, string) {
6065
var bootstrapLookupCmd []string
6166
var handler string
6267
currentWorkingDir := "/var/task" // default value
6368

6469
if len(args) <= 1 {
70+
// set default value to /var/task/bootstrap, but switch to the other options if it doesn't exist
6571
bootstrapLookupCmd = []string{
6672
fmt.Sprintf("%s/bootstrap", currentWorkingDir),
67-
optBootstrap,
68-
runtimeBootstrap,
73+
}
74+
75+
if !isBootstrapFileExist(bootstrapLookupCmd[0]) {
76+
var bootstrapCmdCandidates = []string{
77+
optBootstrap,
78+
runtimeBootstrap,
79+
}
80+
81+
for i, bootstrapCandidate := range bootstrapCmdCandidates {
82+
if isBootstrapFileExist(bootstrapCandidate) {
83+
bootstrapLookupCmd = []string{bootstrapCmdCandidates[i]}
84+
break
85+
}
86+
}
6987
}
7088

7189
// handler is used later to set an env var for Lambda Image support

0 commit comments

Comments
 (0)