Skip to content

Commit

Permalink
valid the bootstraps before passing to NewBootstrapSingleCmd (aws#45)
Browse files Browse the repository at this point in the history
* Pull upstream changes 2021/06 (aws#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]>
  • Loading branch information
wchengru and valerena authored Aug 30, 2021
1 parent 8af3c67 commit 703935c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions cmd/aws-lambda-rie/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,34 @@ func getCLIArgs() (options, []string) {
return opts, args
}

func isBootstrapFileExist(filePath string) bool {
file, err := os.Stat(filePath)
return !os.IsNotExist(err) && !file.IsDir()
}

func getBootstrap(args []string, opts options) (*rapidcore.Bootstrap, string) {
var bootstrapLookupCmd []string
var handler string
currentWorkingDir := "/var/task" // default value

if len(args) <= 1 {
// set default value to /var/task/bootstrap, but switch to the other options if it doesn't exist
bootstrapLookupCmd = []string{
fmt.Sprintf("%s/bootstrap", currentWorkingDir),
optBootstrap,
runtimeBootstrap,
}

if !isBootstrapFileExist(bootstrapLookupCmd[0]) {
var bootstrapCmdCandidates = []string{
optBootstrap,
runtimeBootstrap,
}

for i, bootstrapCandidate := range bootstrapCmdCandidates {
if isBootstrapFileExist(bootstrapCandidate) {
bootstrapLookupCmd = []string{bootstrapCmdCandidates[i]}
break
}
}
}

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

0 comments on commit 703935c

Please sign in to comment.