java.io.IOException:服务器返回URL的HTTP响应代码:403



我正试图通过lambda访问s3对象url,但我得到了以下异常。

java.io.IOException: Server returned HTTP response code: 403 for URL: https://rvs-rta-beta-na.s3.amazonaws.com/Jul-8018/eBooks/eBooksASINReport-EGFUS-SimpleHeader-P94M5TAN9BAYJX0W0FQ1-xls_99c13329-efa7-4084-ab70-5912a652316a_aggregatedLogs.csv: java.lang.RuntimeException
java.lang.RuntimeException: java.io.IOException: Server returned HTTP response code: 403 for URL: https://rvs-rta-beta-na.s3.amazonaws.com/Jul-8018/eBooks/eBooksASINReport-EGFUS-SimpleHeader-P94M5TAN9BAYJX0W0FQ1-xls_99c13329-efa7-4084-ab70-5912a652316a_aggregatedLogs.csv
at com.amazon.metricadapterslambda.lambda.functions.ProcessRVSResults.ProcessRVSResultsHandler.handleRequest(ProcessRVSResultsHandler.java:187)
at com.amazon.metricadapterslambda.lambda.functions.ProcessRVSResults.ProcessRVSResultsLambda.handleRequest(ProcessRVSResultsLambda.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: https://bucketname.s3.amazonaws.com/test-123/abc/FILE_NAME.csv
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
at java.net.URL.openStream(URL.java:1045)
at com.amazon.metricadapterslambda.lambda.functions.ProcessRVSResults.ProcessRVSResultsHandler.getFailedRowDetailsFromRVS(ProcessRVSResultsHandler.java:204)
at com.amazon.metricadapterslambda.lambda.functions.ProcessRVSResults.ProcessRVSResultsHandler.handleRequest(ProcessRVSResultsHandler.java:149)
... 5 more

桶策略:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::ACCOUNTNuMBER:role/LAMBDAROLE"
},
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::BUCKETNAME/*"
}
]
}

代码:-

尝试使用bufferedReader 打开链接

try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8.name()))) 

我认为这个问题与Lambdas如何扮演角色和获取临时会话令牌有关。

查看本文,了解如何允许特定角色访问S3对象。https://levelup.gitconnected.com/how-i-locked-the-whole-company-out-of-an-amazon-s3-bucket-1781de51e4be

还要确保您的函数可以访问S3 bucket本身(除了它的对象(

最佳,Stefan

相关内容

  • 没有找到相关文章

最新更新