To create a Java application that connects to AWS Lambda and triggers a serverless function when a user uploads a file, you'll need to follow these steps:

1. Create an AWS Lambda function with the required code for compressing files.
2. Set up an Amazon S3 bucket to store the uploaded files.
3. Create a Java application using the AWS SDK for Java to interact with AWS services.

Here's a step-by-step guide on how to do this:

Step 1: Create an AWS Lambda function

1. Sign in to your AWS Management Console and navigate to the Lambda service.
2. Click "Create function" and choose "Author from scratch."
3. Enter a name for your function (e.g., "CompressFileFunction") and select a runtime (e.g., Node.js or Python).
4. Add the necessary code to compress the input file. For example, if you're using Node.js, you can use the following code snippet:

```javascript
const zlib = require('zlib');
const fs = require('fs');

exports.handler = async (event) => {
    const inputFile = event.inputFile;
    const outputFile = `${inputFile}.gz`;

    await new Promise((resolve, reject) => {
        const gzip = zlib.createGzip();
        const inputStream = fs.createReadStream(inputFile);
        const outputStream = fs.createWriteStream(outputFile);

        inputStream.pipe(gzip).pipe(outputStream).on('finish', resolve).on('error', reject);
    });

    return { compressedFile: outputFile };
};
```

5. Save and deploy your Lambda function.

Step 2: Set up an Amazon S3 bucket

1. Navigate to the Amazon S3 service in the AWS Management Console.
2. Click "Create bucket" and enter a unique name for your bucket.
3. Follow the prompts to configure your bucket as needed and click "Create."

Step 3: Create a Java application

1. Install the AWS SDK for Java in your project using Maven or Gradle.
2. Configure your AWS credentials by following the instructions in the [official documentation](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html).
3. Create a Java class with a method to upload a file to Amazon S3 and trigger the Lambda function:

```java
import com.amazonaws.services.lambda.AWSLambda;
import com.amazonaws.services.lambda.AWSLambdaClientBuilder;
import com.amazonaws.services.lambda.model.InvokeRequest;
import com.amazonaws.services.lambda.model.InvokeResult;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.PutObjectRequest;

import java.io.File;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;

public class FileCompressor {

    private static final String BUCKET_NAME = "your-bucket-name";
    private static final String LAMBDA_FUNCTION_NAME = "CompressFileFunction";

    public void compressAndUploadFile(File inputFile) {
        // Upload the input file to Amazon S3
        AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient();
        s3Client.putObject(new PutObjectRequest(BUCKET_NAME, inputFile.getName(), inputFile));

        // Invoke the Lambda function
        AWSLambda lambdaClient = AWSLambdaClientBuilder.defaultClient();
        InvokeRequest invokeRequest = new InvokeRequest()
                .withFunctionName(LAMBDA_FUNCTION_NAME)
                .withPayload(String.format("{\"inputFile\": \"%s\"}", inputFile.getName()));
        InvokeResult invokeResult = lambdaClient.invoke(invokeRequest);

        // Get the compressed file name from the Lambda response
        String compressedFileName = parseCompressedFileNameFromResponse(invokeResult.getPayload());

        // Download the compressed file from Amazon S3
        File compressedFile = new File(compressedFileName);
        s3Client.getObject(BUCKET_NAME, compressedFileName, compressedFile);

        System.out.println("Compressed file saved as: " + compressedFile.getAbsolutePath());
    }

    private String parseCompressedFileNameFromResponse(ByteBuffer payload) {
        String responseJson = Charset.forName("UTF-8").decode(payload).toString();
        // Assuming the Lambda function returns a JSON object with a single property "compressedFile"
        return responseJson.substring(responseJson.indexOf(":") + 1, responseJson.length() - 1).replace("\"", "");
    }
}
```

4. Use the `FileCompressor` class in your Java application to compress and upload files:

```java
public class Main {

    public static void main(String[] args) {
        File inputFile = new File("path/to/your/input/file.txt");
        FileCompressor fileCompressor = new FileCompressor();
        fileCompressor.compressAndUploadFile(inputFile);
    }
}
```

Now, when you run your Java application, it will upload the input file to Amazon S3, trigger the AWS Lambda function to compress the file, and download the compressed version of the file back to your local machine.
사용자가 파일을 업로드할 때 AWS Lambda에 연결하고 서버리스 함수를 트리거하는 Java 애플리케이션을 만들려면 다음 단계를 따라야 합니다.

1. 파일 압축에 필요한 코드를 사용하여 AWS Lambda 함수를 생성합니다.
2. 업로드된 파일을 저장할 Amazon S3 버킷을 설정합니다.
3. Java용 AWS SDK를 사용하여 AWS 서비스와 상호 작용하는 Java 애플리케이션을 생성합니다.

이 작업을 수행하는 방법에 대한 단계별 가이드는 다음과 같습니다.

1단계: AWS Lambda 함수 생성

1. AWS 관리 콘솔에 로그인하고 Lambda 서비스로 이동합니다.
2. "함수 생성"을 클릭하고 "처음부터 작성"을 선택합니다.
3. 함수 이름(예: "CompressFileFunction")을 입력하고 런타임(예: Node.js 또는 Python)을 선택합니다.
4. 입력 파일을 압축하는 데 필요한 코드를 추가합니다. 예를 들어 Node.js를 사용하는 경우 다음 코드 스니펫을 사용할 수 있습니다:

```javascript
const zlib = require('zlib');
const fs = require('fs');

exports.handler = async (event) => {
    const inputFile = event.inputFile;
    const outputFile = `${inputFile}.gz`;

    await new Promise((resolve, reject) => {
        const gzip = zlib.createGzip();
        const inputStream = fs.createReadStream(inputFile);
        const outputStream = fs.createWriteStream(outputFile);

        inputStream.pipe(gzip).pipe(outputStream).on('finish', resolve).on('error', reject);
    });

    return { compressedFile: outputFile };
};
```

5. 람다 함수를 저장하고 배포합니다.

2단계: Amazon S3 버킷 설정

1. AWS 관리 콘솔에서 Amazon S3 서비스로 이동합니다.
2. "버킷 생성"을 클릭하고 버킷의 고유 이름을 입력합니다.
3. 메시지에 따라 필요에 따라 버킷을 구성하고 "생성"을 클릭합니다.

3단계: Java 애플리케이션 생성

1. Maven 또는 Gradle을 사용하여 프로젝트에 Java용 AWS SDK를 설치합니다.
2. 공식 문서](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html)의 지침에 따라 AWS 자격 증명을 구성합니다.
3. Amazon S3에 파일을 업로드하고 Lambda 함수를 트리거하는 메서드가 포함된 Java 클래스를 생성합니다:

```java
import com.amazonaws.services.lambda.AWSLambda;
import com.amazonaws.services.lambda.AWSLambdaClientBuilder;
import com.amazonaws.services.lambda.model.InvokeRequest;
import com.amazonaws.services.lambda.model.InvokeResult;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.PutObjectRequest;

import java.io.File;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;

public class FileCompressor {

    private static final String BUCKET_NAME = "your-bucket-name";
    private static final String LAMBDA_FUNCTION_NAME = "CompressFileFunction";

    public void compressAndUploadFile(File inputFile) {
        // Upload the input file to Amazon S3
        AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient();
        s3Client.putObject(new PutObjectRequest(BUCKET_NAME, inputFile.getName(), inputFile));

        // Invoke the Lambda function
        AWSLambda lambdaClient = AWSLambdaClientBuilder.defaultClient();
        InvokeRequest invokeRequest = new InvokeRequest()
                .withFunctionName(LAMBDA_FUNCTION_NAME)
                .withPayload(String.format("{\"inputFile\": \"%s\"}", inputFile.getName()));
        InvokeResult invokeResult = lambdaClient.invoke(invokeRequest);

        // Get the compressed file name from the Lambda response
        String compressedFileName = parseCompressedFileNameFromResponse(invokeResult.getPayload());

        // Download the compressed file from Amazon S3
        File compressedFile = new File(compressedFileName);
        s3Client.getObject(BUCKET_NAME, compressedFileName, compressedFile);

        System.out.println("Compressed file saved as: " + compressedFile.getAbsolutePath());
    }

    private String parseCompressedFileNameFromResponse(ByteBuffer payload) {
        String responseJson = Charset.forName("UTF-8").decode(payload).toString();
        // Assuming the Lambda function returns a JSON object with a single property "compressedFile"
        return responseJson.substring(responseJson.indexOf(":") + 1, responseJson.length() - 1).replace("\"", "");
    }
}
```

4. 4. Java 애플리케이션의 `FileCompressor` 클래스를 사용하여 파일을 압축하고 업로드합니다:

```java
public class Main {

    public static void main(String[] args) {
        File inputFile = new File("path/to/your/input/file.txt");
        FileCompressor fileCompressor = new FileCompressor();
        fileCompressor.compressAndUploadFile(inputFile);
    }
}
```

이제 Java 애플리케이션을 실행하면 입력 파일을 Amazon S3에 업로드하고, AWS 람다 함수를 트리거하여 파일을 압축한 다음, 압축된 버전의 파일을 로컬 머신에 다시 다운로드합니다.