我正在尝试生成客户端可以用来将图像上传到特定S3存储桶的预签名URL。我已经成功生成了对GET文件的请求,如下所示:
GeneratePresignedUrlRequest urlRequest = new GeneratePresignedUrlRequest(bucket, filename);
urlRequest.setMethod(method);
urlRequest.setExpiration(expiration);
Run Code Online (Sandbox Code Playgroud)
其中expiration和method分别是Date和HttpMethod对象。
现在,我试图创建一个URL,以允许用户放置文件,但是我不知道如何设置最大内容长度。我确实找到了有关POST政策的信息,但是我更喜欢在这里使用PUT-我也想避免构造JSON,尽管这似乎不太可能。
最后,一个替代的答案可能是将图像上传从API网关传递到Lambda的某种方法,因此我可以在验证文件类型和大小后将其从Lambda上传到S3(这不理想)。
每当我尝试从Lambda(使用Java)发送带有SES的电子邮件时,都会失败-连接超时。
我已经在与Lambda函数相同的VPC中测试了来自EC2实例的完全相同的代码,并且从那里开始工作(它们具有相同的角色)。我还尝试了在Lambda函数不运行在VPC中的情况下运行它(尽管无论如何都需要将其运行在其中),这也不起作用。
这是相关的代码
SendEmailRequest request = new SendEmailRequest().withSource(from)
.withDestination(destination)
.withMessage(message);
try {
System.out.println("Attempting to send an email through Amazon SES by using the AWS SDK for Java...");
if (client == null) {
client = new AmazonSimpleEmailServiceClient();
client.setRegion(Region.getRegion(Regions.EU_WEST_1));
}
client.sendEmail(request); // this is where the exception is thrown
System.out.println("Email sent!");
} catch (Exception ex) {
ex.printStackTrace();
System.err.println(ex.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
该错误消息指出由于超时而无法连接(至email.eu-west-1 ...)。
有什么想法为什么不能在Lambda上使用吗?