Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 将Aws Cloudfront签名URL与Java一起使用时出现未知密钥消息_Amazon Web Services_Amazon S3_Amazon Cloudfront_Pre Signed Url_Aws Sdk Java - Fatal编程技术网

Amazon web services 将Aws Cloudfront签名URL与Java一起使用时出现未知密钥消息

Amazon web services 将Aws Cloudfront签名URL与Java一起使用时出现未知密钥消息,amazon-web-services,amazon-s3,amazon-cloudfront,pre-signed-url,aws-sdk-java,Amazon Web Services,Amazon S3,Amazon Cloudfront,Pre Signed Url,Aws Sdk Java,当我使用Cloudfront签名URL访问S3 bucket对象时,我在浏览器中收到一个错误代码。我想我在创建SignedUrl时采用了相同的方法 创建了一个简单的S3 bucket,该bucket的设置保持默认 创建了CloudFront发行版,设置如下: Origin Domain Name: URL to the S3 bucket (ie. “bucket-name.s3.amazonaws.com”) Restrict Bucket Access: “Yes” O

当我使用Cloudfront签名URL访问S3 bucket对象时,我在浏览器中收到一个错误代码。我想我在创建SignedUrl时采用了相同的方法

  • 创建了一个简单的S3 bucket,该bucket的设置保持默认

  • 创建了CloudFront发行版,设置如下:

       Origin Domain Name: URL to the S3 bucket (ie. “bucket-name.s3.amazonaws.com”)
       Restrict Bucket Access: “Yes”
       Origin Access Identity: “Create a New Identity”
       Grant Read Permissions on Bucket: “Yes, Update Bucket Policy”
       Restrict Viewer Access: “Yes”
       Trusted Signers: “Self”
    
  • 使用AWS SDK创建了一个JAVA方法,如下所示:

      public static void getSignerURL() throws InvalidKeySpecException, IOException {
    
      Protocol protocol = Protocol.http;
      String distributionDomain = "dh6mxa3xww1tk.cloudfront.net";
      File privateKeyFile = new File("C:\\Users\\ABC\\Downloads\\pk-APKAJCG2GCNVLNLB7BWA.pem");
      String s3ObjectKey = "movie.mp4";
      String keyPairId = "APKAJCG2GCNVLNLB7BWA";  
      Date dateLessThan = DateUtils.parseISO8601Date("2020-11-30T22:20:00.000Z");
      Date dateGreaterThan = DateUtils.parseISO8601Date("2011-11-14T22:20:00.000Z");
      String ipRange = "192.168.0.1/24";
    
      String url1 = CloudFrontUrlSigner.getSignedURLWithCannedPolicy(
                   protocol, distributionDomain, privateKeyFile,
                   s3ObjectKey, keyPairId, dateLessThan);
    
     System.out.println("URL IS : "+url1);
    
    }

但在浏览器中获取如下错误代码:

    <Error>
    <Code>InvalidKey</Code>
    <Message>Unknown Key</Message>
    </Error>
从“您的安全凭据”的CloudFront密钥对部分获取的私钥和密钥对Id。 URL生成正确,但显示错误。即使我将pem文件转换为der格式并使用它,问题仍然存在。
请帮我解决。

我遇到了完全相同的问题。。。找到问题了吗?@jpedro是的,我通过更改日期设置解决了问题。我会给代码链接,如果你想。