Skip to content

Commit c6779f7

Browse files
authored
Merge changes for v1.15 release
Merge changes for v1.15 release
2 parents 23f8171 + 2057ada commit c6779f7

File tree

102 files changed

+6738
-2727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+6738
-2727
lines changed

Diff for: Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ compile-lambda-linux-all:
2121
make ARCH=old compile-lambda-linux
2222

2323
compile-with-docker:
24-
docker run --env GOPROXY=direct -v $(shell pwd):/LambdaRuntimeLocal -w /LambdaRuntimeLocal golang:1.19 make ARCH=${ARCH} compile-lambda-linux
24+
docker run --env GOPROXY=direct -v $(shell pwd):/LambdaRuntimeLocal -w /LambdaRuntimeLocal golang:1.20 make ARCH=${ARCH} compile-lambda-linux
2525

2626
compile-lambda-linux:
27-
CGO_ENABLED=0 GOOS=linux GOARCH=${GO_ARCH_${ARCH}} go build -ldflags "${RELEASE_BUILD_LINKER_FLAGS}" -o ${DESTINATION_${ARCH}} ./cmd/aws-lambda-rie
27+
CGO_ENABLED=0 GOOS=linux GOARCH=${GO_ARCH_${ARCH}} go build -buildvcs=false -ldflags "${RELEASE_BUILD_LINKER_FLAGS}" -o ${DESTINATION_${ARCH}} ./cmd/aws-lambda-rie
2828

2929
tests:
3030
go test ./...

Diff for: cmd/aws-lambda-rie/main.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"runtime/debug"
1212

1313
"github.com/jessevdk/go-flags"
14+
"go.amzn.com/lambda/interop"
1415
"go.amzn.com/lambda/rapidcore"
1516

1617
log "github.com/sirupsen/logrus"
@@ -103,7 +104,7 @@ func isBootstrapFileExist(filePath string) bool {
103104
return !os.IsNotExist(err) && !file.IsDir()
104105
}
105106

106-
func getBootstrap(args []string, opts options) (*rapidcore.Bootstrap, string) {
107+
func getBootstrap(args []string, opts options) (interop.Bootstrap, string) {
107108
var bootstrapLookupCmd []string
108109
var handler string
109110
currentWorkingDir := "/var/task" // default value
@@ -149,5 +150,5 @@ func getBootstrap(args []string, opts options) (*rapidcore.Bootstrap, string) {
149150
log.Panic("insufficient arguments: bootstrap not provided")
150151
}
151152

152-
return rapidcore.NewBootstrapSingleCmd(bootstrapLookupCmd, currentWorkingDir, ""), handler
153+
return NewSimpleBootstrap(bootstrapLookupCmd, currentWorkingDir), handler
153154
}

Diff for: cmd/aws-lambda-rie/simple_bootstrap.go

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package main
5+
6+
import (
7+
"fmt"
8+
"os"
9+
"path/filepath"
10+
11+
"go.amzn.com/lambda/fatalerror"
12+
"go.amzn.com/lambda/interop"
13+
"go.amzn.com/lambda/rapidcore/env"
14+
)
15+
16+
// the type implement a simpler version of the Bootstrap
17+
// this is useful in the Standalone Core implementation.
18+
type simpleBootstrap struct {
19+
cmd []string
20+
workingDir string
21+
}
22+
23+
func NewSimpleBootstrap(cmd []string, currentWorkingDir string) interop.Bootstrap {
24+
if currentWorkingDir == "" {
25+
// use the root directory as the default working directory
26+
currentWorkingDir = "/"
27+
}
28+
29+
// a single candidate command makes it automatically valid
30+
return &simpleBootstrap{
31+
cmd: cmd,
32+
workingDir: currentWorkingDir,
33+
}
34+
}
35+
36+
func (b *simpleBootstrap) Cmd() ([]string, error) {
37+
return b.cmd, nil
38+
}
39+
40+
// Cwd returns the working directory of the bootstrap process
41+
// The path is validated against the chroot identified by `root`
42+
func (b *simpleBootstrap) Cwd() (string, error) {
43+
if !filepath.IsAbs(b.workingDir) {
44+
return "", fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", b.workingDir)
45+
}
46+
47+
// evaluate the path relatively to the domain's mnt namespace root
48+
if _, err := os.Stat(b.workingDir); os.IsNotExist(err) {
49+
return "", fmt.Errorf("the working directory doesn't exist: %s", b.workingDir)
50+
}
51+
52+
return b.workingDir, nil
53+
}
54+
55+
// Env returns the environment variables available to
56+
// the bootstrap process
57+
func (b *simpleBootstrap) Env(e *env.Environment) map[string]string {
58+
return e.RuntimeExecEnv()
59+
}
60+
61+
// ExtraFiles returns the extra file descriptors apart from 1 & 2 to be passed to runtime
62+
func (b *simpleBootstrap) ExtraFiles() []*os.File {
63+
return make([]*os.File, 0)
64+
}
65+
66+
func (b *simpleBootstrap) CachedFatalError(err error) (fatalerror.ErrorType, string, bool) {
67+
// not implemented as it is not needed in Core but we need to fullfil the interface anyway
68+
return fatalerror.ErrorType(""), "", false
69+
}

Diff for: cmd/aws-lambda-rie/simple_bootstrap_test.go

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package main
5+
6+
import (
7+
"os"
8+
"reflect"
9+
"testing"
10+
11+
"go.amzn.com/lambda/rapidcore/env"
12+
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func TestSimpleBootstrap(t *testing.T) {
17+
tmpFile, err := os.CreateTemp("", "oci-test-bootstrap")
18+
assert.NoError(t, err)
19+
defer os.Remove(tmpFile.Name())
20+
21+
// Setup single cmd candidate
22+
file := []string{tmpFile.Name(), "--arg1 s", "foo"}
23+
cmdCandidate := file
24+
25+
// Setup working dir
26+
cwd, err := os.Getwd()
27+
assert.NoError(t, err)
28+
29+
// Setup environment
30+
environment := env.NewEnvironment()
31+
environment.StoreRuntimeAPIEnvironmentVariable("host:port")
32+
environment.StoreEnvironmentVariablesFromInit(map[string]string{}, "", "", "", "", "", "")
33+
34+
// Test
35+
b := NewSimpleBootstrap(cmdCandidate, cwd)
36+
bCwd, err := b.Cwd()
37+
assert.NoError(t, err)
38+
assert.Equal(t, cwd, bCwd)
39+
assert.True(t, reflect.DeepEqual(environment.RuntimeExecEnv(), b.Env(environment)))
40+
41+
cmd, err := b.Cmd()
42+
assert.NoError(t, err)
43+
assert.Equal(t, file, cmd)
44+
}
45+
46+
func TestSimpleBootstrapCmdNonExistingCandidate(t *testing.T) {
47+
// Setup inexistent single cmd candidate
48+
file := []string{"/foo/bar", "--arg1 s", "foo"}
49+
cmdCandidate := file
50+
51+
// Setup working dir
52+
cwd, err := os.Getwd()
53+
assert.NoError(t, err)
54+
55+
// Setup environment
56+
environment := env.NewEnvironment()
57+
environment.StoreRuntimeAPIEnvironmentVariable("host:port")
58+
environment.StoreEnvironmentVariablesFromInit(map[string]string{}, "", "", "", "", "", "")
59+
60+
// Test
61+
b := NewSimpleBootstrap(cmdCandidate, cwd)
62+
bCwd, err := b.Cwd()
63+
assert.NoError(t, err)
64+
assert.Equal(t, cwd, bCwd)
65+
assert.True(t, reflect.DeepEqual(environment.RuntimeExecEnv(), b.Env(environment)))
66+
67+
// No validations run against single candidates
68+
cmd, err := b.Cmd()
69+
assert.NoError(t, err)
70+
assert.Equal(t, file, cmd)
71+
}
72+
73+
func TestSimpleBootstrapCmdDefaultWorkingDir(t *testing.T) {
74+
b := NewSimpleBootstrap([]string{}, "")
75+
bCwd, err := b.Cwd()
76+
assert.NoError(t, err)
77+
assert.Equal(t, "/", bCwd)
78+
}

Diff for: go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module go.amzn.com
22

3-
go 1.19
3+
go 1.20
44

55
require (
66
github.com/aws/aws-lambda-go v1.41.0
@@ -16,7 +16,7 @@ require (
1616
github.com/davecgh/go-spew v1.1.1 // indirect
1717
github.com/pmezard/go-difflib v1.0.0 // indirect
1818
github.com/stretchr/objx v0.5.0 // indirect
19-
golang.org/x/net v0.10.0 // indirect
20-
golang.org/x/sys v0.8.0 // indirect
19+
golang.org/x/net v0.18.0 // indirect
20+
golang.org/x/sys v0.14.0 // indirect
2121
gopkg.in/yaml.v3 v3.0.1 // indirect
2222
)

Diff for: go.sum

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
2222
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
2323
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
2424
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
25-
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
26-
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
25+
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
26+
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
2727
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
2828
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
2929
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3030
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
31-
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
32-
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
33-
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
31+
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
32+
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
33+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
3434
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
3535
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3636
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

Diff for: lambda/agents/agent.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@ func ListExternalAgentPaths(dir string, root string) []string {
2020
}
2121
fullDir := path.Join(root, dir)
2222
files, err := os.ReadDir(fullDir)
23+
2324
if err != nil {
24-
log.WithError(err).Warning("Cannot list external agents")
25+
if os.IsNotExist(err) {
26+
log.Infof("The extension's directory %q does not exist, assuming no extensions to be loaded.", fullDir)
27+
} else {
28+
// TODO - Should this return an error rather than ignore failing to load?
29+
log.WithError(err).Error("Cannot list external agents")
30+
}
31+
2532
return agentPaths
2633
}
34+
2735
for _, file := range files {
2836
if !file.IsDir() {
2937
// The returned path is absolute wrt to `root`. This allows

Diff for: lambda/appctx/appctx.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ type Key int
1313
type InitType int
1414

1515
const (
16-
// AppCtxInvokeErrorResponseKey is used for storing deferred invoke error response.
16+
// AppCtxInvokeErrorTraceDataKey is used for storing deferred invoke error cause header value.
1717
// Only used by xray. TODO refactor xray interface so it doesn't use appctx
18-
AppCtxInvokeErrorResponseKey Key = iota
18+
AppCtxInvokeErrorTraceDataKey Key = iota
1919

2020
// AppCtxRuntimeReleaseKey is used for storing runtime release information (parsed from User_Agent Http header string).
2121
AppCtxRuntimeReleaseKey
2222

2323
// AppCtxInteropServerKey is used to store a reference to the interop server.
2424
AppCtxInteropServerKey
2525

26+
// AppCtxResponseSenderKey is used to store a reference to the response sender
27+
AppCtxResponseSenderKey
28+
2629
// AppCtxFirstFatalErrorKey is used to store first unrecoverable error message encountered to propagate it to slicer with DONE(errortype) or DONEFAIL(errortype)
2730
AppCtxFirstFatalErrorKey
2831

Diff for: lambda/appctx/appctxutil.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,16 @@ func UpdateAppCtxWithRuntimeRelease(request *http.Request, appCtx ApplicationCon
119119
return false
120120
}
121121

122-
// StoreErrorResponse stores response in the applicaton context.
123-
func StoreErrorResponse(appCtx ApplicationContext, errorResponse *interop.ErrorResponse) {
124-
appCtx.Store(AppCtxInvokeErrorResponseKey, errorResponse)
122+
// StoreInvokeErrorTraceData stores invocation error x-ray cause header in the applicaton context.
123+
func StoreInvokeErrorTraceData(appCtx ApplicationContext, invokeError *interop.InvokeErrorTraceData) {
124+
appCtx.Store(AppCtxInvokeErrorTraceDataKey, invokeError)
125125
}
126126

127-
// LoadErrorResponse retrieves response from the application context.
128-
func LoadErrorResponse(appCtx ApplicationContext) *interop.ErrorResponse {
129-
v, ok := appCtx.Load(AppCtxInvokeErrorResponseKey)
127+
// LoadInvokeErrorTraceData retrieves invocation error x-ray cause header from the application context.
128+
func LoadInvokeErrorTraceData(appCtx ApplicationContext) *interop.InvokeErrorTraceData {
129+
v, ok := appCtx.Load(AppCtxInvokeErrorTraceDataKey)
130130
if ok {
131-
return v.(*interop.ErrorResponse)
131+
return v.(*interop.InvokeErrorTraceData)
132132
}
133133
return nil
134134
}
@@ -147,6 +147,20 @@ func LoadInteropServer(appCtx ApplicationContext) interop.Server {
147147
return nil
148148
}
149149

150+
// StoreResponseSender stores a reference to the response sender
151+
func StoreResponseSender(appCtx ApplicationContext, server interop.InvokeResponseSender) {
152+
appCtx.Store(AppCtxResponseSenderKey, server)
153+
}
154+
155+
// LoadResponseSender retrieves the response sender
156+
func LoadResponseSender(appCtx ApplicationContext) interop.InvokeResponseSender {
157+
v, ok := appCtx.Load(AppCtxResponseSenderKey)
158+
if ok {
159+
return v.(interop.InvokeResponseSender)
160+
}
161+
return nil
162+
}
163+
150164
// StoreFirstFatalError stores unrecoverable error code in appctx once. This error is considered to be the rootcause of failure
151165
func StoreFirstFatalError(appCtx ApplicationContext, err fatalerror.ErrorType) {
152166
if existing := appCtx.StoreIfNotExists(AppCtxFirstFatalErrorKey, err); existing != nil {

0 commit comments

Comments
 (0)