简体   繁体   English

尝试从EC2访问AWS S3时为什么会出现403错误

[英]Why do I get a 403 error when attempting to access AWS S3 from EC2

I am wanting to access S3 from a Spring Boot application using Spring Cloud AWS. 我想使用Spring Cloud AWS从Spring Boot应用程序访问S3。 My access to S3 works fine from my desktop, but when I bundle the app up as a WAR file and deploy to an EC2 Tomcat container, I get an 403 exception: 我可以从桌面访问S3,但是将应用程序打包为WAR文件并部署到EC2 Tomcat容器时,出现403异常:

Caused by: com.amazonaws.services.s3.model.AmazonS3Exception: Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: 4F0EBE3A853C6D99)
    at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1078) ~[aws-java-sdk-core-1.9.27.jar:na]
    at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:726) ~[aws-java-sdk-core-1.9.27.jar:na]
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:461) ~[aws-java-sdk-core-1.9.27.jar:na]
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:296) ~[aws-java-sdk-core-1.9.27.jar:na]
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3737) ~[aws-java-sdk-s3-1.9.27.jar:na]
    at com.amazonaws.services.s3.AmazonS3Client.getObjectMetadata(AmazonS3Client.java:1028) ~[aws-java-sdk-s3-1.9.27.jar:na]
    at org.springframework.cloud.aws.core.io.s3.SimpleStorageResource.getObjectMetadata(SimpleStorageResource.java:182) ~[spring-cloud-aws-core-1.0.2.RELEASE.jar:1.0.2.RELEASE]
    at org.springframework.cloud.aws.core.io.s3.SimpleStorageResource.exists(SimpleStorageResource.java:112) ~[spring-cloud-aws-core-1.0.2.RELEASE.jar:1.0.2.RELEASE]

I have an application.yml where I define access to AWS: 我有一个application.yml ,其中定义了对AWS的访问权限:

cloud:
    aws:
        region:
            static: eu-west-1
            auto: false
        credentials:
            accessKey: myaccesskey
            secretKey: somereallylongkeyhere
            instanceProfile: true

This works fine from my desktop. 从我的桌面上可以正常工作。 What see do I need to do to make this work? 要完成这项工作,我需要做什么? I have tried turning on every permission I can see within S3 but I can't seem to get around this. 我尝试打开S3中可以看到的所有权限,但似乎无法解决这个问题。

I had a similar problem where the culprit was an outdated system clock. 我有一个类似的问题,罪魁祸首是过时的系统时钟。 EC2 instances can sometimes drift and IAM API is very sensitive to it. EC2实例有时会漂移,而IAM API对它非常敏感。 Relevant information can be found here: https://github.com/boto/boto/issues/2885 . 相关信息可以在这里找到: https : //github.com/boto/boto/issues/2885

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM