我正在尝试用Java编写一个用于AWS Lambda函数的字节流客户端.我已经创建了Lambda函数作为RequestStreamHandler的实现.该项目的基础是在文档中概述这里.
public class LambdaFunctionHandler implements RequestStreamHandler {
static final String bucket = "anS3bucket";
static final String key = "anS3KeyToAJpegFile";
@Override
public void handleRequest(InputStream input, OutputStream output,
Context context) throws IOException {
AmazonS3 s3Client = new AmazonS3Client(
new EnvironmentVariableCredentialsProvider());
try {
context.getLogger().log("Downloading an object\n");
S3Object s3object = s3Client.getObject(new GetObjectRequest(
bucket, key));
context.getLogger().log("Content-Type: " +
s3object.getObjectMetadata().getContentType()
+ "\n");
InputStream in = s3object.getObjectContent();
int b = 0;
context.getLogger().log("Writing jpeg on output\n");
while ((b = in.read()) > -1) {
output.write(b);
} …Run Code Online (Sandbox Code Playgroud)