线程“ JavaFX应用程序线程” com.amazonaws.services.s3.model.AmazonS3中的异常:访问被拒绝

时间:2019-06-28 21:23:06

标签: amazon-web-services exception amazon-s3 amazon-cognito access-denied

问题出在哪里,我该如何解决?堆栈上的唯一其他类似问题溢出没有帮助。

我正在Maven项目中的Eclipse IDE中为Enterprise Java Developers版本aws-samples/aws-cognito-java-desktop-app on GitHub运行此代码,版本:2019-03(4.11.0),内部版本ID:20190314-1200。

我收到以下错误: (重要的错误消息是“访问被拒绝”。)

Exception in thread "JavaFX Application Thread" com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: FA4BD704133C23A1; S3 Extended Request ID: xmTClQgfl5OVYUeQ45mIBkbe/CA1GvSVmM+VmpT9cwTMox+n+fry6GjB1OdhTpOyRFfmjLBwUQ8=), S3 Extended Request ID: xmTClQgfl5OVYUeQ45mIBkbe/CA1GvSVmM+VmpT9cwTMox+n+fry6GjB1OdhTpOyRFfmjLBwUQ8=
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1639)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1304)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1056)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:743)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:717)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:513)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4319)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4266)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4260)
    at com.amazonaws.services.s3.AmazonS3Client.listBuckets(AmazonS3Client.java:926)
    at com.amazonaws.services.s3.AmazonS3Client.listBuckets(AmazonS3Client.java:932)
    at com.amazonaws.sample.cognitoui.CognitoHelper.ListBucketsForUser(CognitoHelper.java:324)
    at com.amazonaws.sample.cognitoui.MainForm.ShowUserBuckets(MainForm.java:31)
    at com.amazonaws.sample.cognitoui.MainForm.lambda$1(MainForm.java:97)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Node.fireEvent(Node.java:8411)
    at javafx.scene.control.Button.fire(Button.java:185)
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$358(GlassViewEventHandler.java:432)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
    at com.sun.glass.ui.View.notifyMouse(View.java:937)

这是错误消息之前控制台中的内容:

bucketslist = ===========Credentials Details.=========== 
Accesskey = ASIA2IPIEEKPEGGO3EW2
Secret = 25FIoW9eJPczpWKCyaaKHw2Iq+xhM3SdzxAsrslh
SessionToken = AgoJb3JpZ2luX2VjEBwaCXVzLWVhc3QtMSJGMEQCIHqf/tWxrF7qQJuAv7MUtVCQLcomUA3cgPS/rEEKaMi4AiBQxay1snMP98nPCt6LDZZEqVhIyi/3Xn56lkMc4iCRDCqmBQhlEAAaDDcwNTM5ODMxNzcyNiIM20llBNVbiMH2FXa+KoMFqDEQyC/l9JtcMKAg+OUyUPozec7Xfb7uzLPExCEp47lacWIg5DELHrmgCQHTAjFPthaZyyzt1JG0RCi4DCthacWb2TBvxo56e0hBJVLEXeSZ+LFwnNYyiidJrFs7yQxJQfuDYk4JIuY6AEfFm5R1ZfbQ0PJewx+hdAMdJIsnk8mJZ2BBWClGq+9TzPtRj/0pW5/iVGtv7NySKhUU3Cj4DWMAJsFEz6Zw+BWoNHp6EJRQa14cXkDBLvlhZTokGaC5AQD+SUOw5lXB/ScS0zbTcTqpySqoW6HknRIwph1qzWXjdgQPMppPxNGmmI3eI+Rt53ZC4mOVeKi6vSEdWIFRo0a4P7OMgdrJ2RoEI6+pIPuOkCDC/0BcS1K/W/ar7V0SRV5Ae5UnKoasRkTho2+B5juSJBJd9LH+LliVqxAGLdmVwC4AG51c6P530yYOQ7Njlc0HSloYC3oUBu8BcWIgG4JpA+m7s0ts7UVQSs/sbDksOmj8IMsg+oPtCUcnnPIQzO1CKcPMieB/BApLWKLSzLGfpz+GpRFRou42fvnfAtaH+EsHk8/+xuVxO1jzKT6Z4WF1k84r1zN7fO9UOE3exZCLzXhhQHsOyR69mb652N88OGjotxAVBJMfcGWeUYhYYNMHxQUz/lPMH5BxUWb50Qy5/XvJ8b/IH0OSTWhfS6lD6HsUit+c+C66KRAcMhB2ENOzb26LKtl4XyD0AQcBgSnx2rTfqi8zKIDkZSRgq3w09M6ngI4JXMRkHUwyQi3sNlheyB1l6amhqPeQPMWYlLYFgWtWON1nyvJg9Niq0WZvc+7qvFuhK7GRdIOeLY1kGJxqAXqZHiY584zpG1BEfxeEqzCu3tnoBTq1ASXqR+O/61OZNZ4TsL/hy7iD4JYMAdblU++/fi9DP4xNfwrv48q/tu2DrilR8kZzrzS9Eq+TVX68orsXhs1coCMgSRFRRHMQEYq0MpAmN3kKhQ0+M4QfqHkqkjKPu3LDd1kGA7uk1i/3bShnyaO9zV2JbcPBUVXne8AWPeo9e3kHgJepw9PklcJu9rS806zbiVz+lkLlnaBRiXuytgjYbObTv4SjZpGjmL2RO3L6LMT60+GDQcE=
============Bucket Lists===========

因此,我发现错误发生在此代码中标记为“ // error here”的地方:

/**
 * This method returns the details of the user and bucket lists.
 *
 * @param credentials Credentials to be used for displaying buckets
 * @return
 */
String ListBucketsForUser(Credentials credentials) {
    BasicSessionCredentials awsCreds = new BasicSessionCredentials(credentials.getAccessKeyId(), credentials.getSecretKey(), credentials.getSessionToken());
    AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
            .withRegion(Regions.fromName(REGION))
            .build();
    StringBuilder bucketslist = new StringBuilder();

    bucketslist.append("===========Credentials Details.=========== \n");
    bucketslist.append("Accesskey = " + credentials.getAccessKeyId() + "\n");
    bucketslist.append("Secret = " + credentials.getSecretKey() + "\n");
    bucketslist.append("SessionToken = " + credentials.getSessionToken() + "\n");
    bucketslist.append("============Bucket Lists===========\n");

    // error here

    System.out.println("bucketslist = " + bucketslist.toString());

    for (Bucket bucket : s3Client.listBuckets()) {
        bucketslist.append(bucket.getName());
        bucketslist.append("\n");

        System.out.println(" - " + bucket.getName());
    }
    return bucketslist.toString();
}

1 个答案:

答案 0 :(得分:0)

我分配给联合身份的角色没有足够的权限来执行其需要做的事情。我在AWS IAM控制台中为其提供了更多访问权限。