Skip to content

Commit 17dc38a

Browse files
author
lambda-tooling+rie
committed
Update from upstream - 2026-03-27
1 parent c09024d commit 17dc38a

File tree

11 files changed

+60
-24
lines changed

11 files changed

+60
-24
lines changed

.github/workflows/validate-branch-into-main.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: Validate PR Branch into Main
22

3-
permissions:
4-
contents: read
5-
63
on:
74
pull_request:
85
branches:

internal/lambda/rapi/rapi_fuzz_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"unicode"
2222

2323
"github.com/stretchr/testify/assert"
24+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lmds"
25+
2426
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/appctx"
2527
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/extensions"
2628
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/fatalerror"
@@ -187,6 +189,7 @@ func FuzzRestoreErrorHandler(f *testing.F) {
187189
}
188190

189191
func makeRapiServer(flowTest *testdata.FlowTest) *Server {
192+
metadataService := lmds.NewService("test-token")
190193
return NewServer(
191194
"127.0.0.1",
192195
0,
@@ -197,6 +200,7 @@ func makeRapiServer(flowTest *testdata.FlowTest) *Server {
197200
&telemetry.NoOpSubscriptionAPI{},
198201
flowTest.TelemetrySubscription,
199202
flowTest.CredentialsService,
203+
metadataService,
200204
)
201205
}
202206

internal/lambda/rapi/server.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import (
1010
"net/http"
1111

1212
"github.com/go-chi/chi/v5"
13-
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/appctx"
13+
log "github.com/sirupsen/logrus"
14+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lmds"
1415

16+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/appctx"
1517
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/core"
1618
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/interop"
1719
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/rapi/rendering"
1820
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/telemetry"
19-
20-
log "github.com/sirupsen/logrus"
2121
)
2222

2323
const version20180601 = "/2018-06-01"
@@ -56,6 +56,7 @@ func NewServer(
5656
logsSubscriptionAPI telemetry.SubscriptionAPI,
5757
telemetrySubscriptionAPI telemetry.SubscriptionAPI,
5858
credentialsService core.CredentialsService,
59+
metadataService *lmds.Service,
5960
) *Server {
6061

6162
exitErrors := make(chan error, 1)
@@ -76,6 +77,8 @@ func NewServer(
7677
router.Mount(version20210423, CredentialsAPIRouter(credentialsService))
7778
}
7879

80+
router.Mount(lmds.URIPath, http.MaxBytesHandler(metadataService, 0))
81+
7982
return &Server{
8083
host: host,
8184
port: port,

internal/lambda/rapi/telemetry_logs_fuzz_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313

1414
"github.com/google/uuid"
1515
"github.com/stretchr/testify/assert"
16+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lmds"
17+
1618
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/extensions"
1719
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/interop"
1820
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/rapi/handler"
@@ -133,6 +135,7 @@ func makeRapiServerWithMockSubscriptionAPI(
133135
logsSubscription,
134136
telemetrySubscription,
135137
flowTest.CredentialsService,
138+
lmds.NewService("test-token"),
136139
)
137140
}
138141

internal/lambda/rapid/handlers_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import (
1717
"testing"
1818
"time"
1919

20+
"github.com/stretchr/testify/assert"
21+
"github.com/stretchr/testify/mock"
22+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lmds"
23+
2024
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/appctx"
2125
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/core"
2226
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/fatalerror"
@@ -28,9 +32,6 @@ import (
2832
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/supervisor/model"
2933
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/telemetry"
3034
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/testdata"
31-
32-
"github.com/stretchr/testify/assert"
33-
"github.com/stretchr/testify/mock"
3435
)
3536

3637
func BenchmarkChannelsSelect10(b *testing.B) {
@@ -139,7 +140,8 @@ func TestListen(t *testing.T) {
139140

140141
ctx := context.Background()
141142
telemetryAPIEnabled := true
142-
server := rapi.NewServer("127.0.0.1", 0, flowTest.AppCtx, flowTest.RegistrationService, flowTest.RenderingService, telemetryAPIEnabled, flowTest.TelemetrySubscription, flowTest.TelemetrySubscription, flowTest.CredentialsService)
143+
metadataService := lmds.NewService("test-token")
144+
server := rapi.NewServer("127.0.0.1", 0, flowTest.AppCtx, flowTest.RegistrationService, flowTest.RenderingService, telemetryAPIEnabled, flowTest.TelemetrySubscription, flowTest.TelemetrySubscription, flowTest.CredentialsService, metadataService)
143145
err := server.Listen()
144146
assert.NoError(t, err)
145147

internal/lambda/rapid/sandbox.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import (
99
"fmt"
1010
"io"
1111
"sync"
12+
"time"
13+
14+
"github.com/google/uuid"
15+
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lmds"
1216

1317
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/appctx"
1418
"github.com/aws/aws-lambda-runtime-interface-emulator/internal/lambda/core"
@@ -52,7 +56,7 @@ type Sandbox struct {
5256
//
5357
// - Contexts & Data:
5458
// - ctx is used to gracefully terminate Runtime API HTTP Server on exit
55-
func Start(ctx context.Context, s *Sandbox) (interop.RapidContext, interop.InternalStateGetter, string) {
59+
func Start(ctx context.Context, s *Sandbox) (interop.RapidContext, interop.InternalStateGetter, string, string) {
5660
// Initialize internal state objects required by Rapid handlers
5761
appCtx := appctx.NewApplicationContext()
5862
initFlow := core.NewInitFlowSynchronization()
@@ -63,7 +67,18 @@ func Start(ctx context.Context, s *Sandbox) (interop.RapidContext, interop.Inter
6367

6468
appctx.StoreInitType(appCtx, s.InitCachingEnabled)
6569

66-
server := rapi.NewServer(s.RuntimeAPIHost, s.RuntimeAPIPort, appCtx, registrationService, renderingService, s.EnableTelemetryAPI, s.LogsSubscriptionAPI, s.TelemetrySubscriptionAPI, credentialsService)
70+
// Create metadata service with hardcoded AZ ID for RIE
71+
metadataToken := uuid.NewString()
72+
metadataService := lmds.NewService(metadataToken)
73+
74+
// Set hardcoded metadata for RIE (use1-az1 per design)
75+
metadataConfig := lmds.MetadataConfig{
76+
Data: []byte(`{"AvailabilityZoneID":"use1-az1"}`),
77+
MaxAge: 12 * time.Hour,
78+
}
79+
metadataService.UpdateMetadata(metadataConfig)
80+
81+
server := rapi.NewServer(s.RuntimeAPIHost, s.RuntimeAPIPort, appCtx, registrationService, renderingService, s.EnableTelemetryAPI, s.LogsSubscriptionAPI, s.TelemetrySubscriptionAPI, credentialsService, metadataService)
6782
runtimeAPIAddr := fmt.Sprintf("%s:%d", server.Host(), server.Port())
6883

6984
// TODO: pass this directly down to HTTP servers and handlers, instead of using
@@ -105,7 +120,7 @@ func Start(ctx context.Context, s *Sandbox) (interop.RapidContext, interop.Inter
105120

106121
go startRuntimeAPI(ctx, execCtx)
107122

108-
return execCtx, registrationService.GetInternalStateDescriptor(appCtx), runtimeAPIAddr
123+
return execCtx, registrationService.GetInternalStateDescriptor(appCtx), runtimeAPIAddr, metadataToken
109124
}
110125

111126
func (r *rapidContext) HandleInit(init *interop.Init, initSuccessResponseChan chan<- interop.InitSuccess, initFailureResponseChan chan<- interop.InitFailure) {

internal/lambda/rapidcore/env/constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ func predefinedPlatformEnvVarKeys() map[string]bool {
2727
"AWS_LAMBDA_FUNCTION_MEMORY_SIZE": true,
2828
"AWS_LAMBDA_FUNCTION_VERSION": true,
2929
"AWS_LAMBDA_RUNTIME_API": true,
30+
"AWS_LAMBDA_METADATA_API": true,
31+
"AWS_LAMBDA_METADATA_TOKEN": true,
3032
"TZ": true,
3133
}
3234
}

internal/lambda/rapidcore/env/environment.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ func (e *Environment) StoreRuntimeAPIEnvironmentVariable(runtimeAPIAddress strin
6666
e.runtimeAPISet = true
6767
}
6868

69+
// StoreMetadataAPIEnvironmentVariables stores values for AWS_LAMBDA_METADATA_API and AWS_LAMBDA_METADATA_TOKEN
70+
func (e *Environment) StoreMetadataAPIEnvironmentVariables(metadataAPIAddress, metadataToken string) {
71+
e.platform["AWS_LAMBDA_METADATA_API"] = metadataAPIAddress
72+
e.platform["AWS_LAMBDA_METADATA_TOKEN"] = metadataToken
73+
}
74+
6975
// SetHandler sets _HANDLER env variable value for Runtime
7076
func (e *Environment) SetHandler(handler string) {
7177
e.runtime[handlerEnvKey] = handler

internal/lambda/rapidcore/sandbox_api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type SandboxContext struct {
1717
rapidCtx interop.RapidContext
1818
handler string
1919
runtimeAPIAddress string
20+
metadataToken string
2021
}
2122

2223
// initContext and its methods model the initialization lifecycle
@@ -55,6 +56,8 @@ func (s SandboxContext) Init(init *interop.Init, timeoutMs int64) interop.InitCo
5556
}
5657

5758
init.EnvironmentVariables.StoreRuntimeAPIEnvironmentVariable(s.runtimeAPIAddress)
59+
// Metadata API uses the same address as Runtime API
60+
init.EnvironmentVariables.StoreMetadataAPIEnvironmentVariables(s.runtimeAPIAddress, s.metadataToken)
5861
extensions.DisableViaMagicLayer()
5962

6063
// We start initialization handling in a separate goroutine so that control can be returned back to

internal/lambda/rapidcore/sandbox_builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,13 @@ func (b *SandboxBuilder) Create() (interop.SandboxContext, interop.InternalState
172172

173173
// rapid.Start, among other things, starts the Runtime API server and
174174
// terminates it gracefully if the cxt is canceled
175-
rapidCtx, internalStateFn, runtimeAPIAddr := rapid.Start(ctx, b.sandbox)
175+
rapidCtx, internalStateFn, runtimeAPIAddr, metadataToken := rapid.Start(ctx, b.sandbox)
176176

177177
b.sandboxContext = &SandboxContext{
178178
rapidCtx: rapidCtx,
179179
handler: b.handler,
180180
runtimeAPIAddress: runtimeAPIAddr,
181+
metadataToken: metadataToken,
181182
}
182183

183184
return b.sandboxContext, internalStateFn

0 commit comments

Comments
 (0)