com.amazonaws.apigateway.request.context missing in backend @RestController

Offen
#1,551 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
42/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
aws, java, spring-boot
Bereich
api, backend, cloud

Rechercherichtung

Beginne mit dem im Issue gezeigten Einstiegspunkt LambdaHandler und GeographicAddressController und verfolge anschließend, wie der API Gateway request context für Spring-Controller-Attribute bereitgestellt wird. Reproduziere die Anfrage mit den aufgeführten Spring Boot- und Container-Versionen; abgeschlossen ist die Aufgabe, wenn @RequestAttribute den AwsProxyRequestContext einschließlich der Authorizer-Details statt null erhält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Issue: com.amazonaws.apigateway.request.context missing in backend @RestController

To help us debug your issue fill in the basic information below using the options provided

Serverless Java Container version: 2.1.4

Implementations: Spring Boot 3

Framework version: SpringBoot 3.5.3

Frontend service: REST API / API Gateway Proxy Request

Deployment method: SAM

Description

When using Spring Boot 3.5.3 with aws-serverless-java-container-springboot3:2.1.4,
the AwsProxyRequestContext is not being injected into a controller method when annotated with:

@RequestAttribute("com.amazonaws.apigateway.request.context")

This attribute is expected to contain the API Gateway request context, but instead it is always null.

Lambda Handler

import com.amazonaws.serverless.exceptions.ContainerInitializationException;
import com.amazonaws.serverless.proxy.internal.LambdaContainerHandler;
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class LambdaHandler implements RequestStreamHandler {
    private static final SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;

    static {
        try {
            handler = new SpringBootProxyHandlerBuilder<AwsProxyRequest>()
                    .defaultProxy()
                    .initializationWrapper(new InitializationWrapper())
                    .springBootApplication(Application.class)
                    .buildAndInitialize();
        } catch (ContainerInitializationException e) {
            throw new LambdaException("Could not initialize Lambda. ", e);
        }
    }

    @Override
    public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
        handler.proxyStream(inputStream, outputStream, context);
    }
}

Controller

import com.amazonaws.serverless.proxy.model.AwsProxyRequestContext;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class GeographicAddressController {

    private static final String API_GATEWAY_CONTEXT_PROPERTY = "com.amazonaws.apigateway.request.context";

    @GetMapping(path = "/geographicAddress", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Object> get(
            final @RequestHeader HttpHeaders reqHeaders,
            final @RequestParam Map<String, String> params,
            final @RequestAttribute(value = API_GATEWAY_CONTEXT_PROPERTY, required = false) AwsProxyRequestContext requestContext
    ) {
        // requestContext is always null, I would like to get AwsProxyRequestContext , and authorizer details
        return ResponseEntity.ok().build();
    }
}

Expected Behavior

The requestContext parameter should be populated with the AwsProxyRequestContext extracted from the incoming API Gateway event.

Actual Behavior

requestContext is always null inside the controller method.

Steps to Reproduce

  • Deploy a Spring Boot 3.5.3 application with aws-serverless-java-container-springboot3:2.1.4.
  • Use the Lambda handler shown above.
  • Add a controller method with @RequestAttribute("com.amazonaws.apigateway.request.context").
  • Invoke the API Gateway endpoint.
  • Observe that requestContext is always null.
Vorherrschende Sprache
Java
Sterne
1.6k
Forks
575
Ø Merge
1 T. 15 Std.
Gemergte PRs (30 T.)
12

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus aws/serverless-java-container

Alle Issues in aws/serverless-java-container

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.