Skip to content

Commit bef5c4b

Browse files
authored
Merge pull request #194 from aws/develop
Release 1.38
2 parents 3a19ea2 + d71cae7 commit bef5c4b

51 files changed

Lines changed: 2321 additions & 292 deletions

Some content is hidden

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

‎.github/PULL_REQUEST_TEMPLATE.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!--
2+
Thank you for taking the time to send this.
3+
4+
Please read this first: this repository is generated from an internal AWS source of truth, so we
5+
cannot merge pull requests into it directly. We still want your proposal. Yours will be read and
6+
treated as a reference for the change you are describing, and if we adopt your solution we make the
7+
corresponding change internally and credit you in the release notes for the version that ships it.
8+
9+
If what you want is a behaviour change rather than a specific patch, an issue describing your use
10+
case is more effective than a pull request. See CONTRIBUTING.md.
11+
-->
12+
13+
#### What does this change do?
14+
15+
16+
#### Why is it needed? What is the use case?
17+
18+
19+
#### How did you test it?
20+
21+
<!-- Local tests pass through `make integ-tests-and-compile`. -->
22+
23+
24+
#### Checklist
25+
26+
- [ ] I have read [CONTRIBUTING.md](../CONTRIBUTING.md) and understand this pull request will be used
27+
as a reference rather than merged directly
28+
- [ ] I opened an issue first if this is a significant change
29+
- [ ] This change is limited to the behaviour described above, with no unrelated reformatting
30+
- [ ] Local tests pass through `make integ-tests-and-compile`
31+
32+
By submitting this pull request, I confirm that my contribution is made under the terms of the
33+
[Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0).

‎CONTRIBUTING.md‎

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ documentation, we greatly value feedback and contributions from our community.
66
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
77
information to effectively respond to your bug report or contribution.
88

9+
**Please note:** this repository is generated from an internal AWS source of truth, which means we are unable to merge
10+
pull requests into it directly. We very much still want your input -- see
11+
[How we handle contributions](#how-we-handle-contributions) for what happens to an issue or pull request you open, and
12+
how you get credit for a change we adopt.
13+
914

1015
## Reporting Bugs/Feature Requests
1116

12-
We welcome you to use the GitHub issue tracker to report bugs or suggest features.
17+
We welcome you to use the GitHub issue tracker to report bugs or suggest features. Issues are the most effective way to
18+
reach us: a feature request that describes your use case can be picked up and implemented, whereas a pull request cannot
19+
be merged as-is.
1320

1421
When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already
1522
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
@@ -20,25 +27,34 @@ reported the issue. Please try to include as much information as you can. Detail
2027
* Anything unusual about your environment or deployment
2128

2229

23-
## Contributing via Pull Requests
24-
This repository contains the source code and examples for the Runtime Interface Emulator. We will accept pull requests on documentation, examples, bug fixes and the Dockerfiles. We will also accept pull requests, issues and feedback on improvements to the Runtime Interface Emulator. However, our priority will be to maintain fidelity with AWS Lambda’s Runtime Interface on the cloud.
30+
## How we handle contributions
31+
32+
This repository contains the source code and examples for the Runtime Interface Emulator. The code here is generated from
33+
an internal AWS repository, which is the source of truth, and changes flow outward from there. Because of that we cannot
34+
merge a pull request into this repository, even one we agree with.
2535

26-
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
36+
That does not mean we don't want it. Here is what each kind of contribution gets you:
2737

28-
1. You are working against the latest source on the *main* branch.
29-
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
30-
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
38+
* **Feature requests and bug reports are welcome, and are the most useful thing you can send us.** Open an issue
39+
describing the behaviour you want and the use case behind it. Our priority is maintaining fidelity with AWS Lambda's
40+
Runtime Interface in the cloud, so a clear use case is what lets us weigh a change against that.
41+
* **Pull requests are welcome as a reference.** We read them, and a working patch is often the clearest way to explain a
42+
proposal. It will not be merged directly. If we adopt your solution, we make the corresponding change in the internal
43+
repository, and it reaches this repository through the next sync.
44+
* **If we adopt your change, we credit you in the release notes** for the version that ships it.
3145

32-
To send us a pull request, please:
46+
So that we can act on a pull request, please:
3347

34-
1. Fork the repository.
35-
2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
36-
3. Ensure local tests pass through `make integ-tests-and-compile`
37-
4. Commit to your fork using clear commit messages.
38-
5. Send us a pull request, answering any default questions in the pull request interface.
48+
1. Open an issue first to discuss any significant work -- we would hate for your time to be wasted on something we
49+
cannot take.
50+
2. Work against the latest source on the *main* branch.
51+
3. Check existing open, and recently closed, pull requests and issues to make sure someone else hasn't raised it already.
52+
4. Focus on the specific change you are proposing. If you also reformat all the code, it will be hard for us to see what
53+
you are actually suggesting.
54+
5. Ensure local tests pass through `make integ-tests-and-compile`.
3955
6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
4056

41-
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
57+
GitHub provides additional documentation on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
4258
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
4359

4460

@@ -58,4 +74,5 @@ If you discover a potential security issue in this project we ask that you notif
5874

5975
## Licensing
6076

61-
See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
77+
See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your
78+
contribution, including for a pull request we adopt rather than merge.

‎README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Lambda’s orchestrator, or security and authentication configurations. You can
2525
* [To test an image without adding RIE to the image](#to-test-an-image-without-adding-rie-to-the-image)
2626
* [How to configure](#how-to-configure)
2727
* [Level of support](#level-of-support)
28+
* [Contributing](#contributing)
2829
* [Security](#security)
2930
* [License](#license)
3031

@@ -187,6 +188,18 @@ configurations that will not be emulated by this component.
187188
* The component does _not_ support X-ray and other Lambda integrations locally.
188189
* The component supports only Linux, for x86-64 and arm64 architectures.
189190
191+
## Contributing
192+
193+
We welcome feature requests and bug reports through the GitHub issue tracker, and they are the most effective way to
194+
reach us.
195+
196+
This repository is generated from an internal AWS source of truth, so we are unable to merge pull requests into it
197+
directly. You are still welcome to open one: we read them, and a working patch is often the clearest way to explain a
198+
proposal. It is treated as a reference rather than something we merge, and if we adopt your solution we make the change
199+
in the internal repository and credit you in the release notes for the version that ships it.
200+
201+
See [CONTRIBUTING](CONTRIBUTING.md) for details.
202+
190203
## Security
191204
192205
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.26.6
55
require (
66
github.com/aws/aws-lambda-go v1.46.0
77
github.com/go-chi/chi v1.5.5
8-
github.com/go-chi/chi/v5 v5.2.2
8+
github.com/go-chi/chi/v5 v5.4.0
99
github.com/google/uuid v1.6.0
1010
github.com/jessevdk/go-flags v1.5.0
1111
github.com/orcaman/concurrent-map v1.0.0

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
66
github.com/go-chi/chi v1.5.5 h1:vOB/HbEMt9QqBqErz07QehcOKHaWFtuj87tTDVz2qXE=
77
github.com/go-chi/chi v1.5.5/go.mod h1:C9JqLr3tIYjDOZpzn+BCuxY8z8vmca43EeMgyZt7irw=
8-
github.com/go-chi/chi/v5 v5.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618=
9-
github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
8+
github.com/go-chi/chi/v5 v5.4.0 h1:+ufzvFTGKyin26Or5DLrlIDq4ygIDBVcj7oVNeeaYFE=
9+
github.com/go-chi/chi/v5 v5.4.0/go.mod h1:d1IG7GtKPSjPyBP365PH8sAGVHk3qfB/IhjFNRH1wWM=
1010
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
1111
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1212
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=

‎internal/lambda-managed-instances/aws-lambda-rie/internal/app.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (h *HTTPHandler) invoke(w http.ResponseWriter, r *http.Request) {
6969

7070
metrics := invoke.NewInvokeMetrics(nil, &noOpCounter{})
7171
metrics.AttachInvokeRequest(invokeReq)
72-
if err, responseSent := h.app.Invoke(ctx, invokeReq, metrics); err != nil {
72+
if err, responseSent, _ := h.app.Invoke(ctx, invokeReq, metrics, w); err != nil {
7373
logging.Err(ctx, "invoke failed", err)
7474
if !responseSent {
7575
h.respondWithError(w, err)
@@ -93,7 +93,7 @@ func (h *HTTPHandler) respondWithError(w http.ResponseWriter, err rapidmodel.App
9393

9494
type raptorApp interface {
9595
Init(ctx context.Context, req *intmodel.InitRequestMessage, metrics interop.InitMetrics) rapidmodel.AppError
96-
Invoke(ctx context.Context, msg interop.InvokeRequest, metrics interop.InvokeMetrics) (err rapidmodel.AppError, responseSent bool)
96+
Invoke(ctx context.Context, msg interop.InvokeRequest, metrics interop.InvokeMetrics, responseWriter http.ResponseWriter) (err rapidmodel.AppError, responseSent bool, invokePending bool)
9797
}
9898

9999
type noOpCounter struct{}

‎internal/lambda-managed-instances/aws-lambda-rie/internal/invoke/responder.go‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import (
1616
)
1717

1818
type Responder struct {
19-
invokeReq interop.InvokeRequest
20-
body []byte
21-
rw http.ResponseWriter
19+
invokeReq interop.InvokeRequest
20+
body []byte
21+
responseWriter http.ResponseWriter
2222
}
2323

24-
func NewResponder(invokeReq interop.InvokeRequest) *Responder {
24+
func NewResponder(invokeReq interop.InvokeRequest, responseWriter http.ResponseWriter) *Responder {
2525
return &Responder{
26-
invokeReq: invokeReq,
27-
rw: invokeReq.ResponseWriter(),
26+
invokeReq: invokeReq,
27+
responseWriter: responseWriter,
2828
}
2929
}
3030

@@ -60,9 +60,9 @@ func (s *Responder) SendRuntimeResponseTrailers(request invoke.RuntimeResponseRe
6060
s.SendErrorTrailers(trailerError, "")
6161
return
6262
}
63-
s.rw.Header().Set(invoke.СontentTypeHeader, request.ContentType())
64-
s.rw.Header().Set(invoke.RuntimeResponseModeHeader, request.ResponseMode())
65-
if _, err := s.rw.Write(s.body); err != nil {
63+
s.responseWriter.Header().Set(invoke.СontentTypeHeader, request.ContentType())
64+
s.responseWriter.Header().Set(invoke.RuntimeResponseModeHeader, request.ResponseMode())
65+
if _, err := s.responseWriter.Write(s.body); err != nil {
6666
slog.Error("could not write invoke response", "err", err)
6767
}
6868
}
@@ -72,10 +72,10 @@ func (s *Responder) SendError(err invoke.ErrorForInvoker, _ interop.InitStaticDa
7272
}
7373

7474
func (s *Responder) SendErrorTrailers(err invoke.ErrorForInvoker, _ invoke.InvokeBodyResponseStatus) {
75-
s.rw.Header().Set("Error-Type", err.ErrorType().String())
75+
s.responseWriter.Header().Set("Error-Type", err.ErrorType().String())
7676

77-
s.rw.WriteHeader(err.ReturnCode())
78-
if _, err := s.rw.Write([]byte(err.ErrorDetails())); err != nil {
77+
s.responseWriter.WriteHeader(err.ReturnCode())
78+
if _, err := s.responseWriter.Write([]byte(err.ErrorDetails())); err != nil {
7979
slog.Error("could not write invoke error response", "err", err)
8080
}
8181
}

‎internal/lambda-managed-instances/aws-lambda-rie/internal/invoke/responder_test.go‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ func TestResponder_CompleteSuccessFlow(t *testing.T) {
2525
mockRuntimeReq := invoke.NewMockRuntimeResponseRequest(t)
2626
mockInitData := interop.NewMockInitStaticDataProvider(t)
2727

28-
mockInvokeReq.On("ResponseWriter").Return(recorder)
2928
mockInvokeReq.On("MaxPayloadSize").Return(int64(1024))
3029

3130
responseBody := "test response body"
@@ -34,7 +33,7 @@ func TestResponder_CompleteSuccessFlow(t *testing.T) {
3433
mockRuntimeReq.On("ResponseMode").Return("buffered")
3534
mockRuntimeReq.On("TrailerError").Return(nil)
3635

37-
responder := NewResponder(mockInvokeReq)
36+
responder := NewResponder(mockInvokeReq, recorder)
3837
responder.SendRuntimeResponseHeaders(mockInitData, "", "")
3938
result := responder.SendRuntimeResponseBody(context.Background(), mockRuntimeReq, 0)
4039
assert.NoError(t, result.Err)
@@ -55,12 +54,10 @@ func TestResponder_SendErrorFlow(t *testing.T) {
5554
mockInvokeReq := interop.NewMockInvokeRequest(t)
5655
mockInitData := interop.NewMockInitStaticDataProvider(t)
5756

58-
mockInvokeReq.On("ResponseWriter").Return(recorder)
59-
6057
baseErr := io.ErrUnexpectedEOF
6158
appError := model.NewCustomerError("Function.TestError", model.WithCause(baseErr), model.WithErrorMessage("test error"))
6259

63-
responder := NewResponder(mockInvokeReq)
60+
responder := NewResponder(mockInvokeReq, recorder)
6461
responder.SendError(appError, mockInitData)
6562

6663
assert.Equal(t, "Function.TestError", recorder.Header().Get("Error-Type"))
@@ -76,9 +73,7 @@ func TestResponder_RuntimeInvocationErrorFlow(t *testing.T) {
7673
mockInvokeReq := interop.NewMockInvokeRequest(t)
7774
mockInitData := interop.NewMockInitStaticDataProvider(t)
7875

79-
mockInvokeReq.On("ResponseWriter").Return(recorder)
80-
81-
responder := NewResponder(mockInvokeReq)
76+
responder := NewResponder(mockInvokeReq, recorder)
8277
responder.SendRuntimeResponseHeaders(mockInitData, "", "")
8378
responder.SendErrorTrailers(model.NewCustomerError("Runtime.TestError", model.WithErrorMessage("trailer error")), "")
8479

@@ -96,13 +91,12 @@ func TestResponder_ErrorInTheMiddleOfResponse(t *testing.T) {
9691
mockRuntimeReq := invoke.NewMockRuntimeResponseRequest(t)
9792
mockInitData := interop.NewMockInitStaticDataProvider(t)
9893

99-
mockInvokeReq.On("ResponseWriter").Return(recorder)
10094
mockInvokeReq.On("MaxPayloadSize").Return(int64(1024))
10195

10296
responseBody := "test response body"
10397
mockRuntimeReq.On("BodyReader").Return(strings.NewReader(responseBody))
10498

105-
responder := NewResponder(mockInvokeReq)
99+
responder := NewResponder(mockInvokeReq, recorder)
106100
responder.SendRuntimeResponseHeaders(mockInitData, "", "")
107101
result := responder.SendRuntimeResponseBody(context.Background(), mockRuntimeReq, 0)
108102
assert.NoError(t, result.Err)
@@ -123,7 +117,6 @@ func TestResponder_RuntimeResponseTrailerError(t *testing.T) {
123117
mockRuntimeReq := invoke.NewMockRuntimeResponseRequest(t)
124118
mockInitData := interop.NewMockInitStaticDataProvider(t)
125119

126-
mockInvokeReq.On("ResponseWriter").Return(recorder)
127120
mockInvokeReq.On("MaxPayloadSize").Return(int64(1024))
128121

129122
errorType := model.ErrorType("Function.TrailerError")
@@ -138,7 +131,7 @@ func TestResponder_RuntimeResponseTrailerError(t *testing.T) {
138131
mockRuntimeReq.On("BodyReader").Return(strings.NewReader(responseBody))
139132
mockRuntimeReq.On("TrailerError").Return(trailerError)
140133

141-
responder := NewResponder(mockInvokeReq)
134+
responder := NewResponder(mockInvokeReq, recorder)
142135
responder.SendRuntimeResponseHeaders(mockInitData, "", "")
143136
result := responder.SendRuntimeResponseBody(context.Background(), mockRuntimeReq, 0)
144137
assert.NoError(t, result.Err)
@@ -188,10 +181,9 @@ func TestResponder_SendRuntimeResponseBody(t *testing.T) {
188181
mockInvokeReq := interop.NewMockInvokeRequest(t)
189182
mockRuntimeReq := invoke.NewMockRuntimeResponseRequest(t)
190183

191-
mockInvokeReq.On("ResponseWriter").Return(recorder)
192184
tt.setupMocks(mockInvokeReq, mockRuntimeReq)
193185

194-
responder := NewResponder(mockInvokeReq)
186+
responder := NewResponder(mockInvokeReq, recorder)
195187
result := responder.SendRuntimeResponseBody(context.Background(), mockRuntimeReq, 0)
196188

197189
if tt.expectError {

‎internal/lambda-managed-instances/aws-lambda-rie/internal/invoke/rie_invoke_request.go‎

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ type rieInvokeRequest struct {
4242
responseMode string
4343
internalInvocationID string
4444

45-
functionVersionID string
45+
functionVersionID string
46+
resolvedInvokeTimeout time.Duration
4647
}
4748

4849
func NewRieInvokeRequest(request *http.Request, writer http.ResponseWriter) (*rieInvokeRequest, model.AppError) {
@@ -149,22 +150,6 @@ func (r *rieInvokeRequest) BodyReader() io.Reader {
149150
return r.request.Body
150151
}
151152

152-
func (r *rieInvokeRequest) ResponseWriter() http.ResponseWriter {
153-
return r.writer
154-
}
155-
156-
func (r *rieInvokeRequest) SetResponseHeader(key string, val string) {
157-
r.writer.Header().Set(key, val)
158-
}
159-
160-
func (r *rieInvokeRequest) AddResponseHeader(key string, val string) {
161-
r.writer.Header().Add(key, val)
162-
}
163-
164-
func (r *rieInvokeRequest) WriteResponseHeaders(status int) {
165-
r.writer.WriteHeader(status)
166-
}
167-
168153
func (r *rieInvokeRequest) ResponseMode() string {
169154
return r.responseMode
170155
}
@@ -174,7 +159,8 @@ func (r *rieInvokeRequest) UpdateFromInitData(initData interop.InitStaticDataPro
174159
return model.NewClientError(errors.New("sandbox is not initialized"), model.ErrorSeverityError, model.ErrorInitIncomplete)
175160
}
176161

177-
r.deadline = time.Now().Add(time.Duration(initData.FunctionTimeout()) * time.Millisecond)
162+
r.resolvedInvokeTimeout = initData.FunctionTimeout()
163+
r.deadline = time.Now().Add(r.resolvedInvokeTimeout)
178164

179165
if r.functionVersionID != initData.FunctionVersionID() {
180166
return model.NewClientError(nil, model.ErrorSeverityInvalid, model.ErrorInvalidFunctionVersion)
@@ -187,6 +173,14 @@ func (r *rieInvokeRequest) FunctionVersionID() string {
187173
return r.functionVersionID
188174
}
189175

190-
func (r *rieInvokeRequest) InternalInvocationID() string {
191-
return r.internalInvocationID
176+
func (r *rieInvokeRequest) ResolvedFunctionTimeoutMs() int64 {
177+
return 0
178+
}
179+
180+
func (r *rieInvokeRequest) ResolvedInvokeTimeout() time.Duration {
181+
return r.resolvedInvokeTimeout
192182
}
183+
184+
func (r *rieInvokeRequest) LongPollingConfig() *interop.LongPollingConfig { return nil }
185+
186+
func (r *rieInvokeRequest) InternalInvocationID() string { return r.internalInvocationID }

0 commit comments

Comments
 (0)