java localstack lambada — как запустить lambada и просмотреть журналы

#aws-java-sdk #localstack

Вопрос:

Я пытаюсь запустить lambada с помощью localStack и просмотреть журнал …

итак, твой беговой класс выглядит так :

         public class LambdaLoader implements RequestHandler<Object, String> {
      @Override
      public String handleRequest(Object input, Context context) {
          LambdaLogger logger = context.getLogger();
        logger.log(""started"");
            return "Complete";
      }
 

Я управляю им

 public class LambdaLoaderIT {

  @Test
  void handleRequest() throws InterruptedException, IOException {
    AwsClientBuilder.EndpointConfiguration endpointConfiguration =
      new AwsClientBuilder.EndpointConfiguration(
        "http://localhost:4566", Regions.US_EAST_1.getName());
    AWSLambda lambdaClient = createLambdaClient(endpointConfiguration);

    createLambda(lambdaClient);

  }

  private AWSLambda createLambdaClient(
    AwsClientBuilder.EndpointConfiguration endpointConfiguration) {
    return AWSLambdaClientBuilder.standard()
      .withEndpointConfiguration(endpointConfiguration)
      .withCredentials(
        new AWSStaticCredentialsProvider(
          new BasicAWSCredentials("dummyAccessKey", "dummySecretKey")))
      .build();
  }

  private void createLambda(AWSLambda clientLambda) throws IOException {
    CreateFunctionRequest functionRequest = new CreateFunctionRequest();
    functionRequest.setHandler("com.ssp.coreTeam.LambdaLoader::handleRequest");
    functionRequest.setFunctionName("handleRequest");
    functionRequest.setTimeout(900);
    functionRequest.setRuntime("java11");
    functionRequest.setRole("arn:aws:lambda:us-east-1:000000000000:function:handleRequest");

    FunctionCode code = new FunctionCode();
    File file = new File("target/my-lambda-0.0.0-SNAPSHOT.jar");
    FileInputStream fileInputStream = new FileInputStream(file);
    byte[] bytes = IoUtils.toByteArray(fileInputStream);
    code.setZipFile(ByteBuffer.wrap(bytes));
    functionRequest.setCode(code);
    Environment environment = new Environment();
    environment.setVariables(Map.of("LAMBDA_ENV","dev"));
    functionRequest.setEnvironment(environment);
    CreateFunctionResult function = clientLambda.createFunction(functionRequest);
    System.out.println(function);
  }
 

кроме того, именно так я настроил lambada в файле docker-compose (обратите внимание, что LAMBDA_EXECUTOR=локальный ):

   localstack:
    image: 'localstack/localstack'
    ports:
      - '4566:4566'
    environment:
      - SERVICES=lambda,ssm
      - DEBUG=1
      - DATA_DIR=${DATA_DIR- }
      - PORT_WEB_UI=${PORT_WEB_UI- }
      - LAMBDA_EXECUTOR=local
      - KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
      - DOCKER_HOST=unix:///var/run/docker.sock
      - HOST_TMP_FOLDER=${TMPDIR}
    volumes:
      - "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"
 

как я могу увидеть журналы и что там произошло?