Skip to content

Commit b86f257

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into upstream-changes
2 parents d176f7d + 2057ada commit b86f257

File tree

102 files changed

+6747
-2735
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

+6747
-2735
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ compile-lambda-linux-all:
2121
make ARCH=arm64 compile-lambda-linux
2222

2323
compile-with-docker:
24-
docker run --rm --env GOPROXY=direct -v $(shell pwd):/LambdaRuntimeLocal -w /LambdaRuntimeLocal golang:1.19 make ARCH=${ARCH} compile-lambda-linux
24+
docker run --rm --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}" -gcflags="${GC_FLAGS}" -o ${DESTINATION_${ARCH}} ./cmd/localstack
27+
CGO_ENABLED=0 GOOS=linux GOARCH=${GO_ARCH_${ARCH}} go build -buildvcs=false -ldflags "${RELEASE_BUILD_LINKER_FLAGS}" -gcflags="${GC_FLAGS}" -o ${DESTINATION_${ARCH}} ./cmd/localstack
2828

2929
tests:
3030
go test ./...

cmd/aws-lambda-rie/main.go

Lines changed: 3 additions & 2 deletions
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
}
Lines changed: 69 additions & 0 deletions
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+
}
Lines changed: 78 additions & 0 deletions
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+
}

go.mod

Lines changed: 6 additions & 7 deletions
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/sirupsen/logrus v1.9.3
1717
github.com/stretchr/testify v1.8.4
1818
golang.org/x/sync v0.2.0
19-
golang.org/x/sys v0.1.0
19+
golang.org/x/sys v0.14.0
2020
)
2121

2222
require (
@@ -26,11 +26,10 @@ require (
2626
github.com/jmespath/go-jmespath v0.4.0 // indirect
2727
github.com/pmezard/go-difflib v1.0.0 // indirect
2828
github.com/stretchr/objx v0.5.0 // indirect
29-
golang.org/x/mod v0.4.2 // indirect
30-
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
31-
golang.org/x/text v0.3.7 // indirect
32-
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2 // indirect
33-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
29+
golang.org/x/mod v0.8.0 // indirect
30+
golang.org/x/net v0.18.0 // indirect
31+
golang.org/x/text v0.14.0 // indirect
32+
golang.org/x/tools v0.6.0 // indirect
3433
gopkg.in/yaml.v2 v2.2.8 // indirect
3534
gopkg.in/yaml.v3 v3.0.1 // indirect
3635
)

go.sum

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
4646
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
4747
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
4848
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
49-
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
5049
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
50+
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
51+
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
5152
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
5253
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
5354
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
5455
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
5556
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
56-
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 h1:D0B/7al0LLrVC8aWF4+oxpv/m8bc7ViFfVS8/gXGdqI=
57-
golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
57+
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
58+
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
5859
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
5960
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
6061
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
@@ -71,22 +72,23 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
7172
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7273
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7374
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
74-
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
75-
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
75+
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
76+
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
7677
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
7778
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
7879
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
7980
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
8081
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
81-
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
8282
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
83+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
84+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
8385
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
8486
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
85-
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2 h1:BonxutuHCTL0rBDnZlKjpGIQFTjyUVTexFOdWkB6Fg0=
8687
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
88+
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
89+
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
8790
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
8891
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
89-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
9092
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
9193
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
9294
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

lambda/agents/agent.go

Lines changed: 9 additions & 1 deletion
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

lambda/appctx/appctx.go

Lines changed: 5 additions & 2 deletions
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

lambda/appctx/appctxutil.go

Lines changed: 21 additions & 7 deletions
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)