AWS Lambda Java 集成

AWS Lambda Java Integration

我想将我的 Saml SSO 应用程序与 AWS Lambda 集成,但不幸的是我的 Saml 代码接受了它的输入,如下面的代码所示。我需要将 HttpServletRequestHttpServletResponse 作为输入发送到我的 java 处理程序。所以它需要 requestresponse 作为输入,但我的 lambda 处理程序只接受输入作为 JSON 或 java POJO,我对如何进行感到困惑。

    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
    //validation 
    //output
  return authentication;
    }

AWS 团队创建了一个公开请求和响应的无服务器包装器 objects。这应该允许你做你做的事 need.In 他们的处理程序你实现了一个新的接口和他们的底层功能 returns 作为 AwsProxyRequest 和 AwsProxyResponse 对你的请求和响应应该是 children 的 HttpServletRequest 和HttpServletResponse.

代码

public class StreamLambdaHandler implements RequestStreamHandler {
    private SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
    private Logger log = LoggerFactory.getLogger(StreamLambdaHandler.class);

    @Override
    public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
            throws IOException {
        if (handler == null) {
            try {
                handler = SpringLambdaContainerHandler.getAwsProxyHandler(PetStoreSpringAppConfig.class);
            } catch (ContainerInitializationException e) {
                log.error("Cannot initialize Spring container", e);
                outputStream.close();
                throw new RuntimeException(e);
            }
        }

        AwsProxyRequest request = LambdaContainerHandler.getObjectMapper().readValue(inputStream, AwsProxyRequest.class);

        AwsProxyResponse resp = handler.proxy(request, context);

        LambdaContainerHandler.getObjectMapper().writeValue(outputStream, resp);
        // just in case it wasn't closed by the mapper
        outputStream.close();
    }
}

来源 -> https://github.com/awslabs/aws-serverless-java-container